dimanche 10 septembre 2017

Laravel: Unable to locate factory with name

I follow the open tutorial Laravel 5.4 From Scratch and I am on Episode 22 called Testing 101.

I have Laravel installed on a virtual machine with Homestead. This is the content of the file ModelFactory.php

/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(App\User::class, function (Faker\Generator $faker) {
    static $password;

    return [
        'name' => 'Test name',//$faker->name,
        'email' => $faker->unique()->safeEmail,
        'password' => $password ?: $password = bcrypt('secret'),
        'remember_token' => str_random(10),
    ];
});


$factory->define(App\Post::class, function (Faker\Generator $faker) {

    return [
        'user_id' => 1,
        'title' => $faker->sentence,
        'body' => $faker->paragraph
    ];
});

If I login to my Homestead Server like this

vagrant up
vagrant ssh
cd myProjekt/
php artisan tinker

Then I get this output

enter image description here

Now since he tells me that App\Post cannot be found and the name of the user is still invoked by $faker->name instead of the hard coded string Test name I belive that the changes to ModelFactory.php file have not been registered yet.

I made sure that I acutally saved the changes in the file ModelFactory.php. I tried vagrant halt followed up by vagrant up and I also did vagrant reload --provision but the output did not change. I also tried factory(\App\Post::class)->make(); but this was also not found.

Why are the changes to ModelFactory not visible?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire