Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel route with multiple names

Tags:

laravel

routes

Cant i have two names with one route? Something like below:

Route::get('/', 'Admin\HomeController@index')->name(['admin.home', 'planner.home.index']);

Thanks!

like image 318
hayumi kuran Avatar asked Oct 02 '18 02:10

hayumi kuran


1 Answers

This works only if you need the name, not the URL, although it's tricky and sloppy.

Route::get('/', 'Admin\HomeController@index')->name('admin.home');
Route::get('/2', function() {
    return redirect()->route('admin.home')
})->name('planner.home.index');

So if you use route('admin.home') or route('planner.home.index') it will redirects you to the method index in your HomeController.

like image 75
kodfire Avatar answered Nov 15 '22 05:11

kodfire