Question

What is the exact reason to use route filters in Laravel. Filter logic can be added to the controller and that way all the logic will be in the controller, not spread across multiple files.

Was it helpful?

Solution

Typically with the MVC pattern it is preferred that your Controller files are kept pretty lean. That means, they should only handle passing data to and from the Model and View files. Filters applied to routes allow you to apply specific logic, for example validating someone has the necessary roles to view the page, without fattening your controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top