I have a problem when I click edit button in the edit.blade.php
. In update function the PUT method is not supported for this route. Supported methods: POST.
web.php
<?php
Route::get('/', function () {
return view('welcome');
});
Route::get('phones','PhonesController@index');
Route::post('store','PhonesController@store');
Route::delete('destroy/{id}','PhonesController@destroy');
Route::put('edit/{id}', 'PhonesController@edit');
Route::post('update/{id}','PhonesController@update');
View edit.blade.php
<div class="container">
<div class="col-sm-offset-2 col-sm-8">
<div class="panel panel-default">
<div class="panel-heading">
Edit {{$phone->name}}
</div>
<div class="panel-body">
<!-- Display Validation Errors -->
<!-- New Task Form -->
<form action="{{url('update/'.$phone->id)}}" method="POST" class="form-horizontal">
@csrf
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-primary">
@method('put')
<i class="fa fa-edit"></i> Edit
</button>
</div>
</div>
</form>
</div>
</div>
and Controller
public function edit($id)
{
$phone= Phone::find($id);
return view('edit',compact('phone'));
}
public function update(Request $request,$id)
{
$this->validate($request, [
'name' => 'required|max:10',
'model'=>'required'
]);
$phone=new Phone();
$phone->name=$request->input('name');
$phone->model=$request->input('model');
$phone->save();
return back();
}
Just this is a problem I tried another ways but still getting same problem thank you.
<input name="_method" type="hidden" value="PUT">
in your form anywhere, do you? – aynber_method
as PUT, there is nothing here that can send a post request at all – lagbox