Reputation: 10260
I have the following route in my laravel route file:
Route::get('/{id}' , [
'uses' => 'PagesController@show',
'as' => 'getArticle'
]);
The problem with the above route is , its overriding the below route:
Route::resource('admin', 'adminController');
I want to keep my resource route, but how do i keep my resource ? is there a way around this ??
Upvotes: 2
Views: 435
Reputation: 1319
There are two options:
Route::get('/{id}', ...)
after Route::resource(...)
Route::get()
if id
is numeric Route::get('/{id}', ...)->where('id', '[0-9]+');
Upvotes: 1
Reputation: 3704
Modify your route file like this.
Route::resource('admin', 'adminController');
Route::get('/{id}' , [ 'uses' => 'PagesController@show', 'as' => 'getArticle' ]);
Route files executed in the order they are defined.
If you define Route::get('/{id}',....
in the beginning and set your url like http://your-site/admin
, the admin
section will be considers as the id
for the Route::get('/{id}',....
route. So you need to keep it in your mind when you define your route.
Upvotes: 3
Reputation: 104
just move this route in the end of the web.php file.
Route::get('/{id}' , [
'uses' => 'PagesController@show',
'as' => 'getArticle'
]);
Upvotes: 1