M
M
markneedet2019-03-06 02:43:47
Laravel
markneedet, 2019-03-06 02:43:47

Laravel 5.8 can't find class?

Here is the error when seeding data blog_post' not found at C:\OSPanel\domains\poligon.local\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:228 224|if ($this->amount < 1) { 225| return (new $this->class)->newCollection(); 226| } 227| > 228| $instances = (new $this->class)->newCollection(array_map(function () use ($attributes) { 229 | return $this->makeInstance($attributes);


230| }, range(1, $this->amount)));
231|
232| $this->callAfterMaking($instances);

1. create fake post in factory
2. model defined
3. describe in databaseSedder: factory(\App\blog_post::class, 100)->create();
the blog_post model itself:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class blog_post extends Model
{
//
}

factory itself
<?php
use Faker\Generator as Faker;
use App\Models\blog_post;
$factory->define(\App\blog_post::class, function (Faker $faker) {
$title = $faker->sentence(rand(3 , 8), true);
$txt = $faker->realText(rand(1000, 4000));
$isPublished = rand(1, 5) > 1;
$createdAt = $faker->dateTimeBetween('- 3 months',
'- 2 months');
$data = [
'category_id' => rand(1, 11),
'user_id' =>(rand(1, 5) == 5) ? 1 : 2,
'title' => $title,
'slug' =>str_slug($title),
'excerpt' => $faker->text(rand(40, 100)),
'content_raw' => $txt,
'content_html' =>$txt,
'is_published' =>$isPublished,
'published_at' => $isPublished?
$faker->dateTimeBetween('- 2 months', '-1 days') : null,
'created_at' => $createdAt,
'updated_at' => $createdAt,
];
return $data;
});

Tell me what could be the problem??

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kirill Nesmeyanov, 2019-03-06
@SerafimArts

1) From your own example, it is written:

namespace App;
class blog_post extends Model

2) Who taught to name classes like that? Then the main thing is not to show this code to anyone.

R
Roman, 2019-03-06
@procode

use App\Models\blog_post;
Just decide where exactly your class is located - in App or App\Models

V
vism, 2019-03-06
@vism

composer dumpautoload

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question