Organizing Your Laravel Views


Committed to the LaraBrain by: wjgilmore (@wjgilmore) at October 28, 2015 11:23 pm

Bring some sanity to your view directory chaos

Laravel's resources/views directory is the default location for your project views, meaning when you execute return view('about') in a controller action, Laravel will look for a file named about.blade.php in your resources/views directory. However, when working on larger projects dumping all of your views into this directory can quickly become chaotic.

Fortunately you can organize views into logical directories. For instance, inside the LaraBrain application I've created directories called about, tips, admin, categories, and others, each representing a corresponding controller. Within each controller I use Laravel's convenient dot-notation syntax to identify the view and its location. For instance to render the AboutController's index action view, I execute the following statement:

return view('about.index');

To render the TipController's popular action view, I execute:

return view('tip.popular`);

This simple modification to the default will bring a great deal of additional organization to your Laravel projects!