PHP错误:类';第'页;在拉威尔8号修补匠身上找不到
我正在使用工厂模型类在tinker上使用以下命令插入一些虚拟数据: 当我跑的时候PHP错误:类';第'页;在拉威尔8号修补匠身上找不到,php,laravel,factory,tinker,Php,Laravel,Factory,Tinker,我正在使用工厂模型类在tinker上使用以下命令插入一些虚拟数据: 当我跑的时候 composer dump-autoload, php artisan tinker, Page::factory(10)->create() 然后这个错误显示出来 PHP错误:在第1行的/var/www/html/laravel/laravel8-blogeval()d代码中找不到类“Page” 我的模型文件位置app\Models\Page.php <?php namespace App\
composer dump-autoload,
php artisan tinker,
Page::factory(10)->create()
然后这个错误显示出来
PHP错误:在第1行的/var/www/html/laravel/laravel8-blogeval()d
代码中找不到类“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'
]; }
<?php
namespace Database\Factories;
use App\Models\Page;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class PageFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Page::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$title = $this->faker->title;
$slug = Str::slug($title);
$user = User::count() >= 20 ? User::inRandomOrder()->first()->id: User::factory();
return [
'title'=> $title,
'slug' => $slug,
'body' => $this->faker->text(300),
'image' => $this->faker->imageUrl(900, 300),
'user_id' => $user,
];
}
}
如何使用tinker在Laravel 8中插入虚拟数据?谢谢。我建议您的模型使用完整路径,但是您不能直接将计数传递给工厂,您应该使用以下方法: 运行以下命令:
composer dump-autoload,
php artisan tinker,
Page::factory(10)->create()
使用完整路径App\Models\Page::get()显示相同的问题
composer dump-autoload,
php artisan tinker,
Page::factory(10)->create()