That 404 probably means that it does not find any record with that id in the table.
View Error or Bug?
I'm not sure is this error on my code or is it a bug, my view return 404
in my profile.blade.php I have a button pointing to url below
<a href="/users/finances/{{ $finance->id }}/edit">{{ __('Edit') }}</a>
and I specified the route on web.php
Route::get('users/finances/{finance}/edit', 'UserFinancialController@edit);
and in my UserFinancialController.php file I write the method.
public function edit(UserFinance $userFinance)
{
return view('users.financial.edit', compact('userFinance');
}
even when I tried to test dump on my edit method the request doesn't seems to hit the controller method at all
public function edit(UserFinance $userFinance)
{
dd("It's here");
return view('users.financial.edit', compact('userFinance');
}
Is my code wrong or is it some bug?
EDIT:
My app directories as below:
resources/views/users/profile.blade.php
resources/views/users/financial/edit.blade.php
I believe it's your route order that is causing the issue, and for kind of the reason I mentioned.
Route::get('users/profile/{user}', 'ProfileController@index')->name('profile');
Route::get('users/profile/{user}/create', 'ProfileController@create')->name('profile.create');
Route::get('users/profile/{user}/edit', 'ProfileController@edit')->name('profile.edit');
Route::post('users/profile/{user}', 'ProfileController@store')->name('profile.store');
Route::put('users/profile/{user}', 'ProfileController@update')->name('profile.update');
I'm pretty sure your request is being picked up by this route, as it appears higher in the list.
Route::get('users/profile/{user}', 'ProfileController@index')->name('profile');
Try moving that route down lower, below the routes that are more specific (more segments).
Route::get('users/profile/{user}/create', 'ProfileController@create')->name('profile.create');
Route::get('users/profile/{user}/edit', 'ProfileController@edit')->name('profile.edit');
Route::get('users/profile/{user}', 'ProfileController@index')->name('profile');
Route::post('users/profile/{user}', 'ProfileController@store')->name('profile.store');
Route::put('users/profile/{user}', 'ProfileController@update')->name('profile.update');
One thing that helps catch this sort of thing is the laravel debug-bar. It shows the route that was actually used by laravel (among MANY other useful things). It creates a section in your browser to see a lot of laravel variables, queries that were executed, etc. https://github.com/barryvdh/laravel-debugbar
Please or to participate in this conversation.