我正在创建具有角色的用户登录管理系统我在下面运行命令$ php artisan db:seed时遇到错误

问题描述

我正在创建具有角色的用户登录管理系统。在运行命令$ PHP artisan db:seed

时,出现以下错误

ErrorException

file_get_contents(C:\ xampp \ htdocs \ bizzcomputer \ database / dumps / your_database.sql):无法打开流:没有此类文件或目录

  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);
    }
}

解决方法

=IF(ISNA(VLOOKUP(A1,$D$2:$E$4,2,0)),"",VLOOKUP(A1,0))
,

错误消息几乎说明了一切

ErrorException

file_get_contents(C:\ xampp \ htdocs \ bizzcomputer \ database / dumps / your_database.sql):无法打开流:没有此类文件或目录。

它将在存储库的setup( install_requires=[ 'utils @ file://localhost/%s/../utils/' % os.getcwd().replace('\\','/'),],) 目录中寻找名为your_database.sql的文件。

检查该文件是否存在,并为其分配正确的权限