【问题标题】:Problem with Class 'Database\Seeders\ not found找不到类“数据库\播种机\”的问题
【发布时间】:2021-03-24 07:07:57
【问题描述】:

最近我开始练习 laravel/lumen。一切都很好,但现在我在尝试命令时遇到了一个问题:php artisan db:seed 它向我显示了一个错误:找不到 Class 'Database\Seeders\lumenPractice'

我也尝试过: php artisan migrate:fresh --seed 它也无法正常工作并向我显示相同的错误。我正在使用 php 版本 7.4.11enter code here

我的 LumenPractice.php 代码如下:

<?php

namespace App\Models;

use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable;

class LumenPractice extends Model
{
     /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
    
        'name', 
        'gender',
        'country',
    ];
}

我的 DatabaseSeeder.php 代码如下:

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        
        //factory(lumenPractice::class(), 50)->create();
         lumenPractice::factory(count(30))->create();
        // $this->call('UsersTableSeeder');
    }
}

我的 UserFactory.php 代码如下:

<?php

namespace Database\Factories;

use App\Models\LumenPractice;
use Illuminate\Database\Eloquent\Factories\Factory;

class UserFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = LumenPractice::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'gender' =>$gender = $this->faker->randomElement(['male''female'])
            'name' => $this->faker->name($gender),
            'country' => $this->faker->country,
        ];
    }

    
}

【问题讨论】:

    标签: php database class lumen


    【解决方案1】:

    您是否尝试过将lumenPractice::factory(count(30))-&gt;create(); 中的“l”大写?我相信你的意思是写 LumenPractice::factory(count(30))-&gt;create(); 。其他一切似乎都很好。

    【讨论】:

      猜你喜欢
      • 2021-03-19
      • 2018-12-27
      • 2020-04-04
      • 2014-12-08
      • 2012-07-21
      • 1970-01-01
      • 2018-05-20
      • 2019-11-02
      相关资源
      最近更新 更多