简体   繁体   English

Laravel astrotomic 可翻译更新方法

[英]Laravel astrotomic translatable update method

I tried to update a record with this code but no success, i have this error message ... this is probably not the right method我尝试使用此代码更新记录但没有成功,我收到此错误消息...这可能不是正确的方法

public function update(Request $request, int $id)
{
    // dd($id, $request);
    
    $article_data = array();

    foreach ($this -> locales as $locale)
    {
        $article_data[ $locale ] = array(
            'title' => $request -> input( $locale . '_title'),
            'content' => $request -> input( $locale . '_content')
        );

    }

    Article::update($article_data);

    return redirect()->route('admin.article.home');
}

But when I tried this, I receive this error但是当我尝试这个时,我收到这个错误

ErrorException Non-static method Illuminate\\Database\\Eloquent\\Model::update() should not be called statically ErrorException 非静态方法 Illuminate\\Database\\Eloquent\\Model::update() 不应静态调用

I understand that the update method is not the correct one ... So any help would be appreciated :) Thank you我知道更新方法不是正确的方法......所以任何帮助将不胜感激:) 谢谢

this is an example of article_data structure这是 article_data 结构的一个例子

        $article_data = [
        'fr' => [
            'title'       => $request->input('fr_title'),
            'content' => $request->input('fr_content')
        ],
       'en' => [
           'title'       => $request->input('en_title'),
           'content' => $request->input('en_content')
       ],
    ];

Here is the solution这是解决方案

public function update(Request $request, Article $id)
{
    $id->update( $request->all() );

    return redirect()->route('admin.article.home');
}

Thank you :)谢谢 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM