Laravel 5: DB Seed class not found

前端 未结 7 833
孤独总比滥情好
孤独总比滥情好 2021-02-03 21:15

I have this DatabaseSeeder.php:



        
7条回答
  •  长发绾君心
    2021-02-03 22:06

    I ran into the similar error but I was using DB facade DB::table rather than model. I am posting the answer just in case somebody has similar issues.

    The seeder file had namespace namespace Database\Seeders; and laravel was trying to look for DB class inside the namespace and hence the error appeared.

    Class 'Database\Seeders\DB' not found.

    Resolutions:

    • Remove the namespace and run composer dump-autoload
    • OR Add a backslash to \DB::table('stock_categories')->([ ... ]); so Laravel starts looking the DB facade from root (not from the namespace specified)

    Eg,

    \DB::table('MemberInvitation')->insert( [
             'id' => 'BlahBlah' ,//com_create_guid(),
             'partner_id' => 1,
             'fisrt_name' => 'Thats',
             'last_name' => 'Me',
             'email' => 'me@mymail.com',
             'mobile_phone' => '444-342-4234',
             'created_at' => new DateTime
        ] );
    

提交回复
热议问题