Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Joeseph Chen's avatar

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

0 likes
69 replies
Tray2's avatar

That 404 probably means that it does not find any record with that id in the table.

Joeseph Chen's avatar

but my table has that record,

I even tried to dd() on the method, but it seems that it doesn't even hit the method at all

tisuchi's avatar

@dycoda

Actually you are right. It's happening because of no data found in the UserFinance.

The dd("It's here"); won't trigger here because the not found error is triggering before the dd().

To get a more details view, you can try this way-

public function edit($financeid)
{
    // Now you can call and render dd here
    dd("Printing from here.");

    $userFinance = UserFinance::find($financeId);
    return view('users.financial.edit', compact('userFinance');
}

It will print the dd() now.

Nakov's avatar

@dycoda I believe that the route model binding will work if you use the same name as the parameter, so you use {finance} in your url, but then userFinance in your method, that should be the same.. Try this instead:

public function edit(UserFinance $finance)
{
    return view('users.financial.edit', compact('finance');
}
Joeseph Chen's avatar

yeah 100% sure, when i hover on the button, it shows on the left corner of my browser test.site/users/finances/id/edit

Nakov's avatar

so id should be NUMBER not key name :)

Joeseph Chen's avatar

yeah i mean it is a id number,

test.site/users/finances/5/edit like this

Nakov's avatar

Why not use a named route like this:

Route::get('users/finances/{finance}/edit', 'UserFinancialController@edit')->name('finance.edit');

Then to use it

<a href="{{ route('finance.edit', $finance) }}">{{ __('Edit') }}</a>

Make sure that your view is blade.php.

I noticed that in your route you have a missing ' are you missing it in your project as well, in the web.php file?

Joeseph Chen's avatar

actually, I have named my route

Route::get('users/finances/{finance}/edit', 'UserFinancialController@edit')->name('userfinancial.edit');

and I also tried to use route on my button link

<a href="{{ route('userfinancial.edit', $finance->id) }}">{{ __('Edit') }}</a>

but that gets me another error said my route not found, even when clearly I double check so many time if I have a typo, but it keep return error my route not found.

so I changed to writing a url.. but it keep return 404, strange

Joeseph Chen's avatar

tried that also before and even tried the php artisan optimize:clear, still return 404

and also tried to clear cache and cookies of my browser doesn't work, even tried it on different browser also return the same result 404

Nakov's avatar

@dycoda running php artisan route:list in your console you get good results right?

There is a php artisan route:clear command as well in case you have your routes cached. But I would guess that you have an error somewhere..

Try using a callback and check if that will work:

Route::get('users/finances/{finance}/edit', function() {
    dd(request()->all());
});

Does any other route works, and just this one does not?

Joeseph Chen's avatar

yeah i tried to check my route list, and it should point to the right route, and I also tried the callback, but still return 404... this error is like it doesn't even reach my controller method at all.. @nakov

it's only this route, my other route works just fine my other route with the same pattern works perfectly

Route::get('users/profile/{user}/edit', 'ProfileController@edit')->name('profile.edit');

but only this route get this error

Nakov's avatar

@dycoda now the route that you've shared is a different than the one above.

Joeseph Chen's avatar

I mean the route on the previous reply has the same pattern with the route that has error..but that route works just fine..

Nakov's avatar

@dycoda do you have APP_DEBUG=true in your .env file? 404 is not enough :) share a full error please.

Joeseph Chen's avatar

Yeah, the app debug still true because i'm still on development..

It return nothing just 404 page, that makes me hard to debug also..because i don't know what the error..so i post this with the title error or bug..because i doesnt get any ignition error page..just a 404 page.. :(

Nakov's avatar

@dycoda hmm, and nothing even in your log files ? storage/logs?

Joeseph Chen's avatar

well, that's one place I forget to check.. I will try to check it and post again..

Cronix's avatar

Make sure you don't have another route defined earlier in your route file that is responding to GET /users/profile/{placeholder}/edit

I'd do a artisan route:list and make sure there aren't.

If you have 2 routes responding to the same verb (get/post/put) and matching the same url pattern (even if the placeholders are named differently), then only the first one will ever be used and the 2nd one will never be hit.

Sinnbeck's avatar

You can also try posting the contents of web.php here. Maybe someone will spot an error

Joeseph Chen's avatar

here is my route list..

Route::group(['middleware' => ['auth']], function () {
    Route::get('users', 'UserController@index')->name('users.index');
    Route::get('users/create', 'UserController@create')->name('users.create');
    Route::get('users/{user}/edit', 'UserController@edit')->name('users.edit');
    Route::post('register', 'Auth\RegisterController@register')->name('register');
    Route::post('users/{user}', 'UserController@assignTeam')->name('users.team');
    Route::put('users/{user}', 'UserController@update')->name('users.update');
    Route::delete('users/{user}', 'UserController@destroy')->name('users.destroy');

    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');

    Route::get('users/finances/create', 'UserFinancialController@create')->name('userfinancial.create');
    Route::post('users/finances', 'UserFinancialController@store')->name('userfinancial.store');
    Route::get('users/finances/{finance}/edit', 'UserFinancialController@edit')->name('userfinancial.edit');
    Route::put('users/finances/{finance}', 'UserFinancialController@update')->name('userfinancial.update');
}
Joeseph Chen's avatar

Well I tried to double check my php artisan route:list and also my route on web.php many times, but doesn't spot any error, I have already post my route list, maybe someone will spot an error @cronix

Because I'm trying to search for the answer for a few hours now but doesn't found any solutions.. I'm already trying to clear route cache config cache and also php artisan optimize:clear, try it on another browser like firefox, opera but also still return 404 error :(

Nakov's avatar

@dycoda and your error log says nothing more than 404?

Try creating new controller, new route, new everything and compare line by line then :)

Joeseph Chen's avatar

well, I haven't tried to rewrite it again, will try it again and post the result

Cronix's avatar
Cronix
Best Answer
Level 67

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

Next

Please or to participate in this conversation.