Hello guys,
i will start my second laravel project soon. This time i want to develop with different environments (dev, prod). In my last project i developed only on prod... that sucks.
Okay... i know that Laravel has a build in environment-handler. But how do you work with that in the best way?
My idea/Workflow:
Two seperate folders for my laravel project. In each folder my laravel project exists:
dev-project
prod-project
if Dev-Changes are OK then copy file-changes to prod?
additional: if a code-part is only for the dev-environment then you say:
So for example in your .env file you have APP_ENV=local. Laravel now know its in dev mode.
On your production server you can add the env var APP_ENV=production . Now Laravel knows that the system is in production mode.
The common workflow would be to develop locally, push your changes to for example github and envoyer / forge pulls the latest version automatically as soon as you pushed something to your repo.
You dont need two folders - just use git.
If you need some logic in your app to get the current status you can use
if (App::environment('local')) {
// The environment is local
}
Ah okay... so i did understand it correct :) Thank you!
Just another question to the Database Workflow:
If i change/add tables in my local environment, i have to get this changes with artisan on my prod environment manually right? Or do you know an automatic solution as like automatic pulls from git?
Now on your server you need to run php artisan migrate to add the new tables or change columns.
If you are using a service like laravel forge or envoyer, these services does it all for you.
So if you push something to your repo, forge pulls the latest git version and then runs php artisan migrate.
If you are not using something like a auto deployment you have to ssh into your server and run the command manually.