Diego
Diego

Reputation: 105

Laravel 5.5 Naming Route::resource for later use

How can I name my Route::resource so I can call it later in Laravel 5.5?

This works Route::get('newclientTAB', 'NewClientControllerTAB@index')->name('newclientTAB');

This doesn't Route::resource('articles','ArticleController')->name('articles');

Upvotes: 2

Views: 2628

Answers (1)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

If you use:

Route::resource('articles','ArticleController')

Laravel will automatically set names for you routes.

You can run:

php artisan route:list

to see them.

The will have names:

  • articles.index
  • articles.store
  • articles.create
  • articles.show
  • articles.update
  • articles.destroy
  • articles.edit

However if you want to use custom name prefix you can set it like this:

Route::resource('articles','ArticleController', ['names' => 'xyz'])

and then your routes will have names xyz.index, xyz.store and so on

If you want to go further you can also set individual names for example:

Route::resource('articles','ArticleController', ['names' => ['create' => 'foo','update' => 'bar']])

so you can set names only for some routes so you will get foo, bar and articles.index, articles.show and so on

Upvotes: 6

Related Questions