Search code examples
laravellaravel-5.3

auto linking asset files, laravel


I'm pretty new to laravel and so far I'm liking it. Due to some situations where I forgot to include my new js or css files into my layout, Im looking for a way to link all files from those folders.

Im totally willing to create this myself, but I'm not sure what is the best way to do this. So far I have registered some serviceproviders, like viewcomposers and helpers. I was thinking I can make another viewcomposer which collects the folders I want, and link it to the desired layout.

But I don't want to create unnecessary functions (which might already exist). I'm hoping you guys can give me some insight in what's possible in laravel, good/bad practice, useful classes to use etc.


Solution

  • I wouldn't do this.

    I would use Elixir (depending on which version of Laravel you are using) to compile and version my assets. This will mean that you only need to include the references to one file CSS file and one JS file in your view.

    https://laravel.com/docs/5.3/elixir

    You then just need to maintain your gulpfile.

    Versioning your assets also means that you never need to CTRL+F5 to refresh them.