Daniel-Pablo's avatar

Array of ROUTE:GETs... help making the array

Hi, laravel community please I want to create an array of the route get... in this moment I have this

Route::get('/home', 'HomeController@index')->name('home');
Route::get('/advantages', 'advantages@index')->name('advantages');
Route::get('/features', 'features@index')->name('features');
Route::get('/statics', 'statics@index')->name('statics');
Route::get('/about', 'about@index')->name('about');
Route::get('/preorder', 'preorder@index')->name('preorder');

But I read on a post that you can have some kind of array like :


Route::get('/', array(
    'home' => 'HomeController@index', // NEED NAME PARAMETER HERE
    'advantages' => 'CalendarController@showCalendar'  // NEED NAME PARAMETER HERE

SOMEONE CAN HELP ME, THANKS A LOT

0 likes
7 replies
Sinnbeck's avatar

Yes you can use an array, but that is instead of chaining

Route::get('/', array(
    'uses' => 'HomeController@index',
    'name' => 'home'
));

Your own syntax would not work as that would just mean that calling / would call all controllers

Sinnbeck's avatar

The name is for when you need to get the url later on. For example you can do this to get the home url in blade

<a href='{{ route('home') }}'>About</a>

If you the layer change the url of the route it will still work (as it uses the name and not the url)

Daniel-Pablo's avatar

Is there a way to make something like this:

Route::get( array(
 home', 'HomeController@index')->name('home');
advantages', 'advantages@index')->name('advantages');
features', 'features@index')->name('features');
statics', 'statics@index')->name('statics');
about', 'about@index')->name('about');
preorder', 'preorder@index')->name('preorder');

));

this way i know all this calls are get method... Just asking am very new to Laravel am still learning. thanks a lot

Please or to participate in this conversation.