Laravel

How to set routing filters and grouping in laravel ?

Route filters provide a convenient way of limiting access to a given route, which is useful for creating areas of your site which require authentication. There are several filters included in the Laravel framework, including an auth filter, an auth.basic filter, a guest filter, and a csrf filter. These are located in the app/filters.php file.

Defining A Route Filter

If the filter returns a response, that response is considered the response to the request and the route will not execute. Any after filters on the route are also cancelled.

Attaching A Filter To A Route

Attaching A Filter To A Controller Action

Attaching Multiple Filters To A Route

Attaching Multiple Filters Via Array

Specifying Filter Parameters

After filters receive a $response as the third argument passed to the filter:

Pattern Based Filters



You may also specify that a filter applies to an entire set of routes based on their URI.

In the example above, the admin filter would be applied to all routes beginning with admin/. The asterisk is used as a wildcard, and will match any combination of characters.

You may also constrain pattern filters by HTTP verbs:

Named Routes

Named routes make referring to routes when generating redirects or URLs more convenient. You may specify a name for a route like so:

You may also specify route names for controller actions:

Now, you may use the route’s name when generating URLs or redirects:

 

Route Groups

Sometimes you may need to apply filters to a group of routes. Instead of specifying the filter on each route, you may use a route group:

You may also use the namespace parameter within your group array to specify all controllers within that group as being in a given namespace:

 

Sub-Domain Routing

Laravel routes are also able to handle wildcard sub-domains, and will pass your wildcard parameters from the domain:

Registering Sub-Domain Routes

 

Route Prefixing

A group of routes may be prefixed by using the prefix option in the attributes array of a group: