Reputation: 268
I can`t update my table. Maybe you can see where is problem. Edit works fine. It brings value to the fields. If i erase {{ method_field('PUT') }} it saves values normally, but i need to UPDATE
It`s my UPDATE controller
public function update(Request $request, Radar $radar)
{
Radar::update([
'date' => $request->input('date'),
'number' => $request->input('number'),
'distance' => $request->input('distance'),
'time' => $request->input('time'),
]);
return redirect('/radars');
}
Thats how my view looks like:
<form action="{{ url('/radars')}}" method="post" >
{{ method_field('PUT') }}
{{ csrf_field() }}
Routes:
Route::put('radars/{radar}', 'RadarsController@update');
Error:
MethodNotAllowedHttpException
No message
Thank you for help.
Upvotes: 3
Views: 929
Reputation: 941
If you are using resource route, then in your form, you need to change action from:
url('/radars')
to
route('radars.update', $radar)
and keep the following:
{{ method_field('PUT') }}
Upvotes: 0
Reputation: 394
You need to add where statement to tell which record to update and dont
Radar::where('id',$id)->update([
'date' => $request->input('date'),
'number' => $request->input('number'),
'distance' => $request->input('distance'),
'time' => $request->input('time'),
]);
return redirect('/radars');
Upvotes: 0
Reputation: 163768
You need to specify ID:
{{ url('/radars/') . $radar->id }}
Also, you need to use object and not just a model class. Something like:
public function update(Request $request, Radar $radar)
{
$radar->update($request->all());
return redirect('/radars');
}
Upvotes: 1
Reputation: 9329
Looking at it, I think it should be like the below:
<form action="{{ url('/radars/' . $radar->id )}}" method="post" >
If you look, you're posting to /radars
but your route is radars/{driver}
Upvotes: 0