Partial conventions in Laravel
This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.
I've been doing a couple of Laracasts videos, specifically the recent series on building Larabook, and noticed something he was doing that I'm sure will influence a lot of new Laravel developers. I thought I'd propose an alternative, one that I use in my personal and professional life when working with Laravel.
It seems that often, partials are simply being placed in a partials
folder:
However, I prefer to take a more Rails-like approach, whereby instead of having a directory for partials we simply prefix the view with an underscore.
This convention carries on for any other kind of partial too. Say you use a partial for displaying a user, maybe for search results or something like that. You'd underscore and singularise the model name.
Again, these are Rails conventions (though other frameworks might use them too). I like them a lot, and think they're a lot better than having a partials
directory hidden under each of your views folders. But it's a good option that I think should be more widely considered.