Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel naming convention for blade files

I know that naming conventions in Laravel is covered in another question, but blade files are not covered there. I read several blogs and forums and they all offer different approach so I want to ask here:

My controller method is AdminController@listPropertyTypes - which lists and manages the property types..

One blog suggests:

/resources/views/admin/property/types.blade.php

Another blogs suggest underscore or no space:

/resources/views/admin/property_types.blade.php
/resources/views/admin/propertytypes.blade.php

I would personally named this way since it is a view:

/resources/views/admin/property-types.blade.php

Is there a best practice or PSR rule for this?

like image 479
tolga Avatar asked May 14 '20 22:05

tolga


2 Answers

I came across Laravel Best Practices.

Laravel : Best Practices aims to put together all the resources and best practices in using the Laravel Framework. Last Updated: 2020-05-07 12:26:48

Views

You SHOULD use snake_case as file name of your Blade templates

Good

show_filtered.blade.php

Bad

showFiltered.blade.php
show-filtered.blade.php
like image 108
Digvijay Avatar answered Sep 21 '22 03:09

Digvijay


For blade file names, there is no convention as such. But as @James says in his commentary, and I quote

If you are asking about best practices, then one suggestion would be to strictly use CRUD controllers; AdminController@listPropertyTypes is not CRUD. AdminPropertyTypesController@index is more "best practice".

And in this case the best way would be /resources/views/admin/property/types.blade.php.

You can read more about this in Laracon 2017 or in Adam Watham's github repository where he explains it further.

If you are not happy with this result I suggest you also use CamelCase According to the Spatie Guidelines

resources/
  views/
    openSource.blade.php

So, in the controller

class OpenSourceController
{
    public function index() {
        return view('openSource');
    }
}

Instead of looking at unreliable blogs, be guided by the great minds of the Laravel community.

like image 26
MrEduar Avatar answered Sep 20 '22 03:09

MrEduar