0

I have two environments, development and production.

In master.blade layout file, I point to my local js file like that:

<script src="http://192.168.2.40/js/jscript.js" type="text/javascript"></script>

However, I convert this line to the following one for production server.

<script src="http://s.mysite/js/jscript.js" type="text/javascript"></script>

It is very annoyting and error-prone to switch between them. How can I solve this problem in an environment independent way.

1 Answer 1

2

Don't hardcode your addresses.

In your .env file add a new record:

//.. env stuff
APP_URL=http://192.168.2.40 //or http://s.mysite on your production server

Then in your config/app.php if you don't already have it, add a declaration for your url:

'url' => env('APP_URL', 'http://localhost'),
Sign up to request clarification or add additional context in comments.

2 Comments

How would I use 'url' function in blade, and is a new variable, APP_STATIC_URL, more suitable?
@user2356198 You would call it like this -> config('app.url'). And suitable would be up to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.