Seeder command not working. Laravel 5.4
I am new to laravel. I am trying to follow the tutorial in which I am creating a database planter for db. So for this I used the commandphp artisan make:seeder ArticlesTableSeeder
Seeder
class ArticlesTableSeeder extends Seeder
{
public function run()
{
// Let truncate our existing records to start from scratch.
Article::truncate();
$faker = \Faker\Factory::create();
// And now, let create a few articles in our database:
for ($i = 0; $i < 50; $i++) {
Article::create([
'title' => $faker->sentence,
'body' => $faker->paragraph,
]);
}
}
}
Now when I run the command php artisan db:seed --class=ArticlesTableSeeder
I have this error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Article' not found
I have a modal article
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $fillable = ['title', 'body'];
}
What am I doing wrong here? I searched for this error and found that most of them were caused by spelling errors. I think I have no spelling error. What's wrong with this code?
Help will be highly appreciated.
source to share
use App\Article;
class ArticlesTableSeeder extends Seeder
{
public function run()
{
// Let truncate our existing records to start from scratch.
Article::truncate();
$faker = \Faker\Factory::create();
// And now, let create a few articles in our database:
for ($i = 0; $i < 50; $i++) {
Article::create([
'title' => $faker->sentence,
'body' => $faker->paragraph,
]);
}
}
}
source to share
All you have to do is add \App\
before Article
or just adduse \App\Article
class ArticlesTableSeeder extends Seeder
{
public function run()
{
// Let truncate our existing records to start from scratch.
\App\Article::truncate();
$faker = \Faker\Factory::create();
// And now, let create a few articles in our database:
for ($i = 0; $i < 50; $i++) {
\App\Article::create([
'title' => $faker->sentence,
'body' => $faker->paragraph,
]);
}
}
}
source to share