It is not good to have id as fillable due to security issues. In fact you should add id to $guarded.
Use something like this to solve your issue
$data = $moneyTransfer->update($request->all())->where("id", $request->get("id"));
Hello everyone newbee here... I used Laravel 7 and Vue JS.
I tried to update a record using vue js. When I log the request I have this data
[2020-09-23 04:32:47] local.INFO: array (
'id' => 9,
'name' => 'PS Bank',
)
but my update is not working... this is my controller
public function update(Request $request, MoneyTransfer $moneyTransfer)
{
$this->validate($request, [
'name' => 'required'
]);
$data = $moneyTransfer->update($request->all());
\Log::info($request->all());
}
Do I need to include id in my fillable in the model? this is the model.
protected $fillable = ['name'];
Thank you and God bless
Try
public function update(Request $request, MoneyTransfer $moneyTransfer)
{
$this->validate($request, [
'name' => 'required'
]);
$moneyTransfer
->where("id", $request->get("id"))
->update($request->all());
return ['message' => 'Updated the user info'];
}
Please or to participate in this conversation.