I'm trying to populate a Laravel 5.6 project DB - following the offial docs - without success. php artisan db:seed throws this exception:
Symfony\Component\Debug\Exception\FatalThrowableError : Class 'App\Item' not found
at /Applications/MAMP/htdocs/greylab/inventario/greylab_inventario/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:217
Exception trace:
1 Illuminate\Database\Eloquent\FactoryBuilder::make([]) /Applications/MAMP/htdocs/greylab/inventario/greylab_inventario/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:167
2 Illuminate\Database\Eloquent\FactoryBuilder::create() /Applications/MAMP/htdocs/greylab/inventario/greylab_inventario/database/seeds/ItemTableSeeder.php:14
I already tried most of the common suggestions provided from the community, like this one, as well as:
- Trying with
composer self-update+composer dump-autoload; - On my
composer.jsontheautoloadproperty is set as is:
"autoload": { "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\\": "app/" } },
(Tried to put classmap in autoload-dev too).
Here's the situation:
ItemFactory.php
<?php
use Faker\Generator as Faker;
// Definizione dati test
$factory->define(App\Item::class, function (Faker $faker) {
return [ ...]
}
ItemTableSeeder.php
<?php
use Illuminate\Database\Seeder;
class ItemTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(App\Item::class, 25)->create();
}
}
DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call(ItemTableSeeder::class);
}
}
- At last, I tried to put dependencies directly in sources too:
use App\Item; use Illuminate\Database\Seeder;
by removing the App\ prefix and leave only Item::class in the argument:
factory(Item::class, 25)->create();
All these tries didn't helped, so I'm actually stuck. If anyone could show me the way, it should be really appreciated.
Thanks in advance to all.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire