I'm trying to setup routes in Laravel using
Route::get('/post/{id}', 'PostController@index');
Route::get('/post/new', 'PostController@create');
But when I go to mysite.com/post/new
its runs the index function thinking its an {id}.
So I'm wondering if I can force /new to go to the create function or if I have to change /post/ to something different.
Thanks in advance for the help!
Also important !! .The order of route declaration matters. Try this
Route::get('/post/new', 'PostController@create');
Route::get('/post/{id}', 'PostController@index');
and you ll notice that your app is able to identify new
as a different route from {id}
.
That happens because route resolver searches until it finds the first pattern matching the route
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With