Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5: How to enable environment based public resources like css, js, images

we have built a multi environment application over laravel 5 with environment based configurations and views, now the problem arises when we try to use environment based public resources like css, js and images, as they are in public directory and does not recursive merge things like in configurations file. can we somehow control it with environment settings etc.

for example: I have two domains with almost same functionality but differs in some configuration and design, like for example site_1 shows header navigation links on the top while the site_2 does not show header navigation links in top so we can somehow manage it in the configuration site_1.config.settings.header and set values to on or off.

like image 730
smkhan Avatar asked Jun 03 '16 07:06

smkhan


People also ask

Can I use CSS in laravel?

Laravel Mix provides a clean, expressive API over compiling SASS or Less, which are extensions of plain CSS that add variables, mixins, and other powerful features that make working with CSS much more enjoyable.

Can I use JavaScript in laravel?

Laravel does not require you to use a specific JavaScript framework or library to build your applications. In fact, you don't have to use JavaScript at all. However, Laravel does include some basic scaffolding to make it easier to get started writing modern JavaScript using the Vue library.


1 Answers

well as per my understanding you are using multiple environment files which varies deployment to deployment, in larvel you can override enivronment variables from environment files and can use one main environment file to override variables like in .env file you can define the APP_ENV = site_1 and can create new environment file named .site_1.env and override all the environment variables which are different for that deployment.

about the public resources you can do the sort of same alike configuration scheme but as you know these files do not recursive merge so you can create a same file in the public/site_1/filename.ext and when adding these files in your templates you can append the environment name as directory to lookup for those files.

like image 142
Muzammil Naseer Avatar answered Sep 22 '22 08:09

Muzammil Naseer