Answer the question
In order to leave comments, you need to log in
How can I change the default save request to the database in Laravel?
Good day to all!
The essence of the question is this:
There is a table in the database that stores the values of network adapters, so the "id" field was not created in the table, and the "mac" field was assigned as the key field, since the physical addresses themselves are unique.
To save the network adapter data after editing, I wrote the following function:
public function saveNic (Request $request)
{
$data = $request->all();
$host = $data['host'];
unset ($data['host']);
$tmp= Networkcard::select(['mac', 'name', 'network', 'wol'])->where('mac',$data['mac'])->get();
$nic=$tmp[0];
$nic->fill($data);
$nic->save();
return redirect("/host/".$host);
}
Answer the question
In order to leave comments, you need to log in
Per model:
protected $primaryKey = 'mac';
public $incrementing = false;
Networkcard::where('mac', $request->get('mac'))->update($request->all());
return redirect()->back(); // Думаю это подойдёт
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question