I am creating user login management system with roles. I am getting error as, below when I run the command $ php artisan db:seed
ErrorException
file_get_contents(C:\\xampp\\htdocs\\bizzcomputer\\database/dumps/your_database.sql): failed to open stream: No such file or directory
at C:\xampp\htdocs\bizzcomputer\database\seeds\DatabaseSeeder.php:26
22| // Remove foreign keys for now
23| DB::statement('SET FOREIGN_KEY_CHECKS = 0');
24|
25| // Now we seed using our database dump of
> 26| DB::unprepared(file_get_contents($sql));
27|
28| // Enable foreign keys
29| DB::statement('SET FOREIGN_KEY_CHECKS = 1');
30|
1 C:\\xampp\\htdocs\\bizzcomputer\\database\\seeds\\DatabaseSeeder.php:26 file_get_contents("C:\\xampp\\htdocs\\bizzcomputer\\database/dumps/your_database.sql")
2 C:\\xampp\\htdocs\\bizzcomputer\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php:37 DatabaseSeeder::run()
DatabaseSeeder
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// Get the databse dump we wish to use
$sql = base_path('database/dumps/your_database.sql');
if ($sql) {
// Remove foreign keys for now
DB::statement('SET FOREIGN_KEY_CHECKS = 0');
// Now we seed using our database dump of
DB::unprepared(file_get_contents($sql));
// Enable foreign keys
DB::statement('SET FOREIGN_KEY_CHECKS = 1');
$this->call(RolesTableSeeder::class);
$this->call(UsersTableSeeder::class);
}
}
}
UsersTableSeeder
<?php
use App\User;
use App\Role;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
User::truncatte();
DB::table('role_user')->truncate();
$adminRole = Role::where('name', 'admin')->first();
$authorRole = Role::where('name', 'author')->first();
$userRole = Role::where('name', 'user')->first();
$admin = User::create([
'name' => 'Admin User',
'email' => 'admin@admin.com',
'password' => Hash::make('password')
]);
$author = User::create([
'name' => 'Author User',
'email' => 'author@author.com',
'password' => Hash::make('password')
]);
$user= User::create([
'name' => 'Generic User',
'email' => 'user@user.com',
'password' => Hash::make('password')
]);
$admin->roles()->attach($adminRole);
$author->roles()->attach($authorRole);
$user->roles()->attach($userRole);
}
}
//Remove foreign keys for now
DB::statement('SET FOREIGN_KEY_CHECKS = 0');
$this->call(RolesTableSeeder::class);
$this->call(UsersTableSeeder::class);
// Enable foreign keys
DB::statement('SET FOREIGN_KEY_CHECKS = 1');
The error message pretty much says it all
ErrorException
file_get_contents(C:\\xampp\\htdocs\\bizzcomputer\\database/dumps/your_database.sql): failed to open stream: No such file or directory.
It is looking for a file called your_database.sql
within the database/dumps
directory within your repository.
Check that this file exists and that it has the correct permissions assigned to it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.