Reputation: 267
I have in my View:
<a href="/agents/{{ $property->user_id }}/{{ $property->id }}/edit" class="btn-sm">Edit</a></td>
But when I put 1-50 in my $property->user_id parameter, it leads to a property.
I have Route::get('/agents/{agent}/{id}/edit', 'AgentController@edit');
in my web.php
file.
Route File:
Route::get('/properties/', 'PropertyController@index');
Route::get('/properties/{property}', 'PropertyController@show');
Route::get('/agents/{agent}', 'AgentController@index');
Route::get('/agents/{agent}/{id}/edit', 'AgentController@edit');
Route::post('/agents/{agent}', 'AgentController@update')->name('agent.property.update');
This is my Controller code:
public function edit($id)
{
$property = Property::find($id);
return view('agents.edit', compact('property'));
}
I don't understand this behavior in Laravel, it's not what I intend and I just want to make the route work correctly.
Upvotes: 0
Views: 45
Reputation: 906
Laravel gives both agent_id and property_id to the controller as parameter. You are using agent_id only and assuming it as property id.
public function edit($agent_id, $property_id)
{
$property = Property::find($property_id);
return view('agents.edit', compact('property'));
}
Upvotes: 2
Reputation: 4153
Based on your route file, I think you should put this route:
Route::get('/agents/{agent}/{id}/edit', 'AgentController@edit');
above this one:
Route::get('/agents/{agent}', 'AgentController@index');
Upvotes: 0