我正在使用工厂模型类在修补程序上使用此命令插入一些虚拟数据:当我运行时
composer dump-autoload,
php artisan tinker,
Page::factory(10)->create()
Run Code Online (Sandbox Code Playgroud)
然后这个错误显示
PHP 错误:在/var/www/html/laravel/laravel8-blogeval()'d第 1 行代码中未找到“Page”类
我的模型文件位置app\Models\Page.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Page extends Model {
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title',
'slug',
'body',
'excerpt',
'image',
'thumb',
'view_count',
'user_id',
'meta_keywords',
'meta_description',
'social_image',
'order',
'published_at',
'is_active',
'is_destroy'
]; }
Run Code Online (Sandbox Code Playgroud)
我的工厂文件位置 database/factories/PageFactory.php
<?php
namespace Database\Factories;
use App\Models\Page;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class PageFactory …Run Code Online (Sandbox Code Playgroud)