I have a Laravel 5.8 project and I have created this form for updating a title of a record:
<form action="{{ route('popups.update', ['id'=>$popup->id]) }}" method="POST">
@csrf
<label for="title" class="control-label">Title</label>
<input type="text" id="title" name="title" class="form-control" value="{{ $popup->title }}">
<button hljs-string">" type="submit">Submit</button>
</form>
And this is the Controller method for updating:
public function update(Request $request, $id)
{
try{
dd($id);
}catch (\Exception $e) {
dd($e);
}
return redirect()->back();
}
But whenever I submit this, I get this error:
The given data was invalid.
I don't really know what's going wrong here? So if you know, please let me know...
CodePudding user response:
If you are using Route::resource
then method must be PUT/PATCH in form
CodePudding user response:
It should be something like this if you're using the Route::resource('popups', PopupsController::class)
<form action="{{ route('popups.update', $popup->id) }}" method="POST">
@csrf
<label for="title" class="control-label">Title</label>
<input type="text" id="title" name="title" class="form-control" value="{{ $popup->title }}">
<button hljs-string">" type="submit">Submit</button>
</form>
you dont have to pass an array to the route params