I am trying to add a super user in my laravel project. I have but the error occors.
The use statement with non-compound name 'SuperAdminSeeder' has no effect", "E:\github\LARAVEL\Deal-Ocean\database\seeds\DatabaseSeeder.php", ["E:\github\LARAVEL\Deal-Ocean\vendor\composer/../../database/seeds/DatabaseSeeder.php"]
SuperAdminSeeder.php
<?php
use App\Role;
use App\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class SuperAdminSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$role = Role::create(['name' => 'super_admin']);
$user = User::create(['email' => 'imrulhasan273@email.com', 'imrulhasan' => bcrypt('secret')]);
DB::table('role_user')->insert(['user_id' => $user->id, 'role_id' => $role->id]);
}
}
On the above query I am creating a super user with id name and role. And also create their role_id and user_id in pivot table.
DatabaseSeeder.php
<?php
use SuperAdminSeeder;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
// $this->call(UserSeeder::class);
$this->call(SuperAdminSeeder::class);
}
}
Your DatabaseSeeder
is not in a dedicated namespace; it is in the global namespace. Because of this, you don't need to use
any other classes that are also in the global namespace.
Since SuperAdminSeeder
is also in the global namespace, the use SuperAdminSeeder;
statement in your DatabaseSeeder
does not do anything (except cause the error).
Remove the use SuperAdminSeeder;
statement.