laravel

Proper Laravel Route And View Naming Conventions

When it comes to proper route and view naming conventions in Laravel, it is generally acceptable to use resourcePlural.action so here are some examples:

photos.index
photos.create
photos.store
photos.show
photos.edit
photos.update
photos.destroy<

We also have route() helper. Just like the url(), it’s intended to be used in views to simplify linking to a named route. If the route has no parameters, you can simply pass the route name: (route(‘members.index’)) and receive a route string.

If it has parameters, pass them in as an array as the second parameter like we did in this example.

In general, I recommend using route names instead of paths to refer to your routes, and therefore using the route() helper instead of the url() helper. Sometimes it can be a little clumsy – for example, if you are working with multiple subdomains, but it provides an incredible level of flexibility to later change the application’s routing structure without major penalty.

 

About the author

Avatar

laravelrecipies