search

Home  >  Q&A  >  body text

How does Laravel store data into the same ID?

I am writing a website backend configuration page. There is only one data table for this data, namely ID=1 and no id=2. Updated data modifications are all covered in id=1

But how to save the following code to ID=1?

public function edit()
    {
        
       $configs = new Configs();
       
       //这个ID传输 在模版是<input type="hidden" name="id" value="1" />
       
       $configs->id = Request::input('id');
       $configs->web_name = Request::input('web_name');
       $configs->web_add = Request::input('web_add');
       $configs->web_email = Request::input('web_email');
       $configs->web_copy = Request::input('web_copy');
       $configs->web_keywords = Request::input('web_keywords');
       $configs->web_description = Request::input('web_description');
       
      //问题在这里了,如何直接保存到数据库ID1里呢 这样写好像不对
       $configs = Configs::find(1);
       $configs->save();

     return redirect('/admin/config');
    }
过去多啦不再A梦过去多啦不再A梦2867 days ago387

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 16:57:27

    will$configs=new Configs();改为$configs=Configs::find(1);

    Then comment out the following $configs = Configs::find(1)...

    or the second method:

    Configs::where('id','=',1)->update([...]);

    reply
    0
  • Cancelreply