My Routes Are Returning a 404, How to Fix Them

My Routes are Returning a 404, How can I Fix Them?

Have you tried adding this to your routes file instead Route::get('user', "user@index")?

The piece of text before the @, user in this case, will direct the page to the user controller and the piece of text after the @, index, will direct the script to the user function public function get_index().

I see you're using $restful, in which case you could set your Route to Route::any('user', 'user@index'). This will handle both POST and GET, instead of writing them both out separately.

My Route are Returning a 404, How can I Fix Them?

I guess just because of the way you gave parameter in route(web.php).
You don't need to add a $ sign to the parameter. simply right like below.

Route::get('impersonate/{user_id}', 'HomeController@impersonate')->name('impersonate');

Add get it from controller like the same way uh getting.

public function impersonate($user_id){
echo $user_id; die;
$user = User::find($user_id);
Auth::user()->impersonate($user);
return redirect()->route('home');
}

Laravel 8 custom routes return 404 while using resource

A full explanation can be found at https://stackoverflow.com/a/62952620/9004987 (thanks to @Espresso).

Summary:

When the resource route is registered at the beginning it will create some routes. Example:

GET   /clients/{client}   show   clients.show

And when other custom routes (such as /clients/entries) are registered after the resource route then it will conflict with the resource URI (since it has the same pattern).

Solution:

Define the custom routes before the resource route.

Laravel getting 404 error when creating new route

Moved my comment to a little bit explained answer.

So, in your route collection, you have two conflicting routes

Route::get('/{user}', 'ProfilesController@index')->name('profil');

and

Route::get('/alerte', 'PaginaAlerte@index')->name('alerte');

Imagine that Laravel is reading all routings from top to bottom and it stops to reading next one after the first match.

In your case, Laravel is thinking that alerte is a username and going to the ProfilesController@index controller. Then it tries to find a user with alerte username and returning 404 because for now, you don't have a user with this username.

So to fix 404 error and handle /alerte route, you just need to move the corresponding route before /{username} one.

But here is the dilemma that you got now. What if you will have a user with alerte username? In this case, the user can't see his profile page because now alerte is handling by another route.

And I'm suggesting to use a bit more friendly URL structure for your project. Like /user/{username} to handle some actions with users and still use /alerte to handle alert routes.

Laravel route returning error 404 when attempt is made to pass value to controller function

Check it out the route list using this command

php artisan route:list

//this command will show all the routes in your application

If your route not listed on that route list checkout for routes with same Url on your route manually on routes file.

if you found change the url & use this command to clear cache

php artisan optimize:clear

i have found the comment of you on last answer.
check out for route model binding . i think you have to add
a

public function showCust( $loanApplicationCustId)
{

$customerInformation = customerInfoModel::where('Cust_id', $loanApplicationCustId))->first();

return view('admin.loanApplictions.showCustView', compact(['customerInformation', 'loanApplication']));
}

It should be like this .. i hope it works for you......
else share your project git repo link

Laravel 9 Route problem return 404 NOT FOUND

There might be a conflict base on your route order and the image you've posted. As you can see you have resource for your route which in this case this conflict might happen base on route order, and your laravel is actually trying to get a post instead of loading creategif route.

Which in this case every time you try to get access to creategif route, your application is actually trying to load a post base on 'communities.posts' route.

Sample Image

So base on this conflict in your route order, this is working fine and create or any other routes related to 'communities.posts' should work fine, but in other-hand creategif in URL might recognized as a route related to 'communities.posts' resource.

Move your route to top, or in this case just above 'communities.posts' route, don't forget to clear route cache.

Route::group(['middleware' =>['auth', 'verified']], function (){

Route::get('communities/{community}/posts/creategif', [\App\Http\Controllers\CommunityPostController::class, 'creategif']);
Route::resource('communities', \App\Http\Controllers\CommunityController::class);
Route::resource('communities.posts', \App\Http\Controllers\CommunityPostController::class);
Route::resource('posts.comments', \App\Http\Controllers\PostCommentController::class);


Route::get('posts/{post_id}/vote/{vote}', [\App\Http\Controllers\CommunityPostController::class, 'vote'])->name('post.vote');
});


Related Topics



Leave a reply



Submit