Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel php artisan db:seed leads to "use" statement error

When I try to run php artisan db:seed I get the following error:

The use statement with non-compound name 'DB' has no effect

I have written my own seeder file which I have included below, based on a snippet from the doc. As you can see I am using the use DB shortcut - is this what the problem is?

<?php  use Illuminate\Database\Seeder; use Illuminate\Database\Eloquent\Model; use DB;  class ClassesTableSeeder extends Seeder {     /**      * Run the database seeds.      *      * @return void      */     public function run()     {         DB::table('classes')->delete();         DB::table('classes')->insert([             'class_name'    => 'Test course 111',             'class_id'      => '1',             'location_name' => 'Barnes',             'location_id'   => '1',             'date'          => '2015-06-22',             'month'         => '06/2015',             'start_time'    => '08:00',             'end_time'      => '16:00',             'places'        => '19',             'places_left'   => '19',             'price'         => '155.00'         ]);     } } 
like image 309
V4n1ll4 Avatar asked Jun 27 '15 11:06

V4n1ll4


People also ask

How to seed specific seeder in Laravel?

Writing SeedersA seeder class only contains one method by default: run . This method is called when the db:seed Artisan command is executed. Within the run method, you may insert data into your database however you wish. You may use the query builder to manually insert data or you may use Eloquent model factories.

How to insert data using seeder in Laravel?

Use Laravel seeder to insert data to database in laravel 8 If you wish to run seed on one table at a time, example if you want to run only UserSeeder. Just execute php artisan db:seed --class=UserSeeder. Now check database to see user inserted.

How to create seeding in Laravel?

Laravel Seeding Creating a Seeder To create seeders, you may use the make:seeder Artisan command. All seeders generated will be placed in the database/seeds directory. Generated seeders will contain one method: run . You may insert data into your database in this method.


1 Answers

In PHP the use statement is more of an alias than import. So since the ClassesTableSeeder class isn't in a defined namespace, you don't need to import the DB class. As a result you can remove use DB entirely.

like image 93
user2479930 Avatar answered Oct 14 '22 08:10

user2479930