yes,order your routes with the most specific first. Anything with a parameter should be considered a wildcard, matching all routes.
Jul 6, 2017
5
Level 13
Order of routes in web.php
I'm currently on lesson: Laravel 5.4 From Scratch: Rendering Posts.
I made an interesting observation. If the order of routes in my web.php is this:
// Create new post form
Route::get('posts/create', 'PostsController@create');
Route::post('posts/', 'PostsController@store');
// Show individual post
Route::get('/posts/{post}', 'PostsController@show');
..then url: blog.app/posts/create works absolutely fine. However, if I change it to
// Show individual post
Route::get('/posts/{post}', 'PostsController@show');
// Create new post form
Route::get('posts/create', 'PostsController@create');
Route::post('posts/', 'PostsController@store');
then Laravel thinks that I'm trying to fetch results from database with 'id' = 'create' and throws an exception.
It looks like the order of the routes matters. Just out of curiosity, is there any way to handle this (in fairly large projects with multiple routes) ?
Please or to participate in this conversation.