I get the title error when I run command:

php artisan db:seed

My screenshot: enter image description here

I have no idea where this problem comes from. I was searching for code examples and solution but I haven't found anything :(

ArticlesTableSeeder.php

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
// use Laracasts\TestDummy\Factory as TestDummy;

class ArticlesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        factory(App\Models\Article::class, 30)->create();
    }
}

ArticleFactory.php

<?php

namespace Database\Factories;

use App\Models\Model;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class ModelFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = App\Models\Article::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'title' => $faker->text(50),
            'body' => $faker->text(200)
        ];
    }
}

数据库 seeder 机.php

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        $this->call(ArticlesTableSeeder::class);
    }
}

提前感谢您的帮助!

推荐答案

在laravel 8中,默认路由名称空间被删除.

try 改变:

ArticlesTableSeeder.php:

 factory(App\Models\Article::class, 30)->create();

收件人:

\App\Models\Article::factory()->count(30)->create(); 

ArticleFactory.php:

protected $model = App\Models\Article::class;

收件人:

protected $model = \App\Models\Article::class;

你可能不得不改变:

 'title' => $faker->text(50),
            'body' => $faker->text(200)

收件人:

 'title' => $this->faker->text(50),
        'body' => $this->faker->text(200)

Laravel相关问答推荐

Laravel Livewire与自定义JS有关的多姆问题

在Laravel Lumen中迭代连接查询数据

如何在控制器中获取所需参数?

如何避免谷歌翻译翻译:参数

在 laravel 中查询此类数据的最佳做法是什么?

如何在 Laravel Eloquent Collection 数组之前添加一个键值对?

处理程序类中的错误 - Laravel

Carbon现在时间错了

PHP 中的 Http 响应代码枚举

用 laravel 表单确认删除?

Laravel 5 - Php artisan语法错误

将 Laravel .env 变量添加到 Vue 组件

数组的旧输入?

是否可以将路由参数传递给 Laravel 中的控制器构造函数?

无法声明类 Controller,因为该名称已在使用中

Laravel 获取文件内容

Laravel 5 事件处理程序未触发

Carbon解析到 ISO8601

在我的编辑器中管理上传文件的最佳方式?

Laravel 5.2 验证错误未出现在Blade中