Support the ongoing development of Laravel.io →
Requests Eloquent Forms

I have a resource route in my application and I think the update method is never called because theres the show method that has the same URL (/leads/{id}). Even though I have the form method set to PUT on the update form it's still using the show method.

Please help

Show method of LeadsController:

public function show($id)
{
    $lead = Lead::findOrFail($id);
    return view('leads.lead',compact('lead'));
}

Update method of LeadsController:

public function update(UpdateLeadRequest $request, $id)
{   
    $lead = Lead::find($id);
    $tmp = ['email'=>'UPDATED'];
    $lead->update($tmp);
    return view('leads.lead',compact('lead'));
}

Form to update leads:

<form action="{{action('LeadsController@update',['id'=>$lead->id])}}" method="put">
				<input type="hidden" name="_token" value="{{csrf_token()}}" />
				<input type="hidden" name="_method" value="put" />
				<div class="input-group">
					<label for="email">Email:</label>
					<input type="email" name="email" placeholder="Email" class="form-control" value="{{$lead->email}}" />
				</div><br />
				<input type="submit" class="btn btn-primary" value="Save"/>
			</form>
Last updated 3 years ago.
0

Show me your routes

0

Thanks mirbatworks but I figured it out, for future reference my form should have been like this:

<form action="{{action('LeadsController@update',['id'=>$lead->id])}}" method="post">
<input type="hidden" name="_method" value="put" />

method put is no valid for forms, instead I have to use POST and send a hidden field named _method with the value put

Thanks anyway

0

If you have in controller route with { id } Something like this:

Route::get('leads/{id}', 'LeadsController@show');
Route::get('leads/update', 'LeadsController@update');

Your controller will always load show method even if your url is leads/update because of your {id}

In that case you need to change sequences

//first:
Route::get('leads/update', 'LeadsController@update');
// than:
Route::get('leads/{id}', 'LeadsController@show');
Last updated 9 years ago.
0

i am using a resource route so that does not apply in my case

Route::resource('LeadsController');
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jcamilo93 jcamilo93 Joined 27 Dec 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.