elderyn
elderyn

Reputation: 37

Laravel UserTableSeeder

I have started developing a new website with Laravel and AngularJS.

When I create my UserTable I want to populate it with some values using php artisan db:seed, but I get the following message:

[Symfony\Component\Debug\Exception\FatalErrorException] parse error, expecting `')''

Here is my code for DatabaseSeeder.php

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        $this->call('UserTableSeeder');

        $this->command->info('User Table seeded');

        Model::reguard();
    }
}

and UserTableSeeder.php

<?php

class UserTableSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
    DB::table('users')->delete();

        User::create(array(

            'first_name'    => 'Thomas',
            'last_name'     => 'ERAUSQUIN',
            'email'         => '[email protected]',
            'username'      => 'etadmin',
            'password'      => Hash::make('test'); //hashes our password nicely for us

        ));

    }

}

I have already tried running composer dump-autoload
Thank you in advance for your help.

Upvotes: 1

Views: 1302

Answers (2)

elderyn
elderyn

Reputation: 37

ok thank that solve my problem, but now he give me this new error.

    [Symfony\Component\Debug\Exception\FatalErrorException]  
  Class 'Seeder' not found

I have try to add this before my class into UserTableSeeder.php

use Illuminate\Database\Seeder; use Illuminate\Database\Eloquent\Model;

but message error is

[Symfony\Component\Debug\Exception\FatalErrorException]  
  Class 'User' not found

so don't really understand what happen

PS: I find the good way

here the good code for code work perfectly

<?php

use Illuminate\Database\Seeder;
use App\User as User;

class UserTableSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
    DB::table('users')->delete();

        User::create(array(

            'first_name'    => 'Thomas',
            'last_name'     => 'ERAUSQUIN',
            'email'         => '[email protected]',
            'username'      => 'etadmin',
            'password'      => Hash::make('test') //hashes our password nicely for us

        ));

    }

}

So before your class User for add one or some user you need add just after

this code

use Illuminate\Database\Seeder;
use App\User as User;

Second part for my answer find here

Regard

Upvotes: 1

BenOfTheNorth
BenOfTheNorth

Reputation: 2872

You need to remove the semi-colon you have here:

Hash::make('test');

To:

Hash::make('test')

You are ending the statement early by leaving the semi-colon there and PHP doesn't know how to process it properly.

Upvotes: 3

Related Questions