Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why doesn't this seeder class code work in production?

I have this seeder class that works/runs in my development setup:

class OwnerSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        if(config('owner.owner_first_name')) {
            $user = User::firstOrCreate(
                 ['email' => config('owner.owner_email')], [
                     'first_name' => config('owner.owner_first_name'),
                     'last_name' => config('owner.owner_last_name'),
                     'mobile_phone_number' => config('owner.owner_mobile_phone_number'),
                     'password' => bcrypt(config('owner.owner_password')),
                     'email_verified_at' => now(),
                     'identity_verified_at' => now(),
                 ]
             );
         }
        
         $user->assignRole('owner')
         ->givePermissionTo(Permission::all());
    }
}

But when I run it in production, I get the error ‘Undefined variable $user’. What can I do to resolve this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

What I can see there is that your config is different in production and your local: the owner.owner_first_name key doesn’t seem to exist in production, which means that the code within the if statement will never be executed and will jump straight to the $user variable, which of course won’t be set (that happens only if the if gets executed.

Take a review on your config and start from there.

Good luck!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading