Laravel4 seed specific environment
NickName:Sven van Zoelen Ask DateTime:2014-03-28T00:01:37

Laravel4 seed specific environment

We're are developing multiple applications based on Laravel 4. These applications run on the same webserver.

The Laravel4 environment detection is based on the hostname which sucks because we have multiple applications on the same machine. We created a work-around in the detection area so that it will set the environment based on the url.

We run the artisan --env=my_env migrate command when we update the applications DB. The problem is in the seeding, the seeding command doesn't have a env option so it will try to seed the db based on the hostname wich will not be correct.

I'm trying all day to find a solution but I can't find any on the Internet and my attempts to build a new command is just taking too much time and energy.

Does someone knows how to set the environment when seeding?

PS: I run the commands on the server through Grunt and I know the environment -inject it into the command-.

Copyright Notice:Content Author:「Sven van Zoelen」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/22693006/laravel4-seed-specific-environment

Answers
Antonio Carlos Ribeiro 2014-03-27T16:14:04

You pointed it very well, Laravel environment guessing sucks the way we use to use it, but you can change that:\n\nThis is how I do set my environment flawlessly, so I don't have to deal with hostnames and still don't get my local environment conflict with staging and production.\n\nCreate a .environment file in the root of your application and define your environment and add your sensitive information to it:\n\n<?php\n\nreturn array(\n\n 'APPLICATION_ENV' => 'development', /// this is where you will set your environment\n\n 'DB_HOST' => 'localhost',\n 'DB_DATABASE_NAME' => 'laraveldatabase',\n 'DB_DATABASE_USER' => 'laraveluser',\n 'DB_DATABASE_PASSWORD' => '!Bassw0rT',\n\n);\n\n\nAdd it to your .gitignore file, so you don't risk having your passwords sent to Github or any other of your servers.\n\nRight before $app->detectEnvironment, in the file bootstrap/start.php, load your .environment file to PHP environment:\n\nforeach(require __DIR__.'/../.environment' as $key => $value) \n{\n putenv(sprintf('%s=%s', $key, $value));\n}\n\n\nAnd then you just have to use it:\n\n$env = $app->detectEnvironment(function () {\n\n return getenv('APPLICATION_ENV'); // your environment name is in that file!\n\n});\n\n\nAnd it will work everywhere, so you don't need to have separate dirs for development and production anymore:\n\n<?php\n\nreturn array(\n\n 'connections' => array(\n\n 'postgresql' => array(\n 'driver' => 'pgsql',\n 'host' => getenv('DB_HOST'),\n 'database' => getenv('DB_DATABASE_NAME'),\n 'username' => getenv('DB_DATABASE_USER'),\n 'password' => getenv('DB_DATABASE_PASSWORD'),\n 'charset' => 'utf8',\n 'prefix' => '',\n 'schema' => 'public',\n ),\n\n ),\n\n);\n\n\nNote that I don't set a fallback: \n\nreturn getenv('APPLICATION_ENV') ?: 'local';\n\n\nBecause I want it to fail on every server I deploy my app to, to never forget configuring my environment on them.\n\nThen you just have to select the environment in your DatabaseSeeder class:\n\npublic function run()\n{\n if( App::environment() === 'development' )\n {\n $this->call('UserTableSeeder');\n } \n}\n",


More about “Laravel4 seed specific environment” related questions

Laravel4 seed specific environment

We're are developing multiple applications based on Laravel 4. These applications run on the same webserver. The Laravel4 environment detection is based on the hostname which sucks because we have

Show Detail

How to deploy Laravel4 on heroku?

I am using Laravel4 and mysql. I want deploy this application in Heroku. Not sure what steps need to followed to deploy it on Heroku. Because I am using php artisan commands to create db, seed ...

Show Detail

set.seed() in a local environment

Is it possible to use the set.seed() in a local environment not affecting the following random number generation? It is common use to set the seed in some functions to get reproducible results but I

Show Detail

Laravel 4 DB seed issue

I am trying to create a database seed file. Here how is it: class UsersSeeder extends DatabaseSeeder { public function run() { $users = [ [ 'email' =&gt; '[email protected]'..

Show Detail

Generate specific string from specific seed

I would like to generate a specific string from a specific seed, example: string data = &quot;LargeBigData&quot; string seed = &quot;seed1&quot; string generatedStringSeed = ToSeed (data, seed) //

Show Detail

Lock environment but not .Random.seed

Is it possible to lock the global environment and still allow .Random.seed to be set or removed? The default behavior of lockEnvironment() is too aggressive for my use case. lockEnvironment(global...

Show Detail

how to match hashed password in laravel4

I am working on change password function in laravel4 . I got stuck into one point that how to match hashed password on database with the new password we enter. I know this that laravel4 Auth produc...

Show Detail

seed job does not passes environment variable to groovy dsl script

I am using job-dsl-plugin. In my seed job 'a' I am setting a build environment variable using 'Inject environment variables to the build process' option and providing an environment variable as fol...

Show Detail

Using a specific seed in the `RANDOM_NUMBER` algorithm

I'm looking to use a specific set of seeds for the intrinsic function RANDOM_NUMBER (a PRNG). What I've read so far is that the seed value can be set via calling RANDOM_SEED, specifically RANDOM_SE...

Show Detail

Laravel4 NotFoundHttpException in Wamp Server

I am reading Laravel4 quick start tutorial Laravel4 quick start I have installed laravel4 on Wamp server in Windows . I was able to access home page which says "you have arrived". Later in ther

Show Detail