Reputation: 612
I'm trying to make refresh option in my Laravel project. I made a public function refresh()
in my CarsController
. The idea is to make created_at
get current time because my cars are ordered by orderBy('created_at'. 'desc')->get();
. So this is my public function refresh()
in my CarsController
:
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function refresh($id)
{
$car = Car::find($id);
$car->created_at = Carbon::now();
$car->save();
return redirect('/cars');
}
This is my Form
in blade:
{!!Form::open(['action' => ['CarsController@refresh', $car->id], 'method' => 'PUT'])!!}
{{Form::hidden('_method', 'PUT')}}
{{Form::submit('Refresh', ['class' => 'btn btn-success'])}}
{!!Form::close()!!}
And this is in my web.php
route:
Route::get('/cars/{id}', 'CarsController@refresh');
What I'm doing wrong? Please help. Thanks!
Upvotes: 0
Views: 123
Reputation: 3972
HTML forms do not support PUT, PATCH or DELETE actions.To solve this, please change your form into this.
{!!Form::open(['action' => ['CarsController@refresh', $car->id], 'method' => 'GET'])!!}
{{Form::submit('Refresh', ['class' => 'btn btn-success'])}}
{!!Form::close()!!}
you will remove this line because laravel will expect that your having a put request instead of a get request.
{{Form::hidden('_method', 'PUT')}}
Upvotes: 2
Reputation: 2387
For method overloading try the following code:
{{Form::hidden('_method', 'GET')}}
Upvotes: 0