Gavin
Gavin

Reputation: 741

Factories on Laravel 5.2 not working as expected

I have a very strange problem with Laravel 5.2 factories.

I have recently upgraded from Laravel 5.1 to 5.2 following the upgrade guide on the Laravel website. All works as exepected except one factory. Yes the others work ok. Here are two of the factories:

$factory->define(App\Client::class, function (Faker\Generator $faker) {
    return [
        'name'              => $faker->company,
        'building'          => $faker->buildingNumber,
        'street'            => $faker->streetName,
        'town'              => $faker->city,
        'postcode'          => $faker->postcode,
        'country'           => 'UK',
        'telephone'         => $faker->phoneNumber,
        'fax'               => $faker->phoneNumber,
    ];
});

$factory->define(App\Shift::class, function (Faker\Generator $faker) {
    return [
        'client_id'         => $faker->numberBetween($min = 1, $max = 15),
        'user_id'           => $faker->numberBetween($min = 1, $max = 15),
        'start'             => $faker->dateTimeBetween($startDate='now', $endDate='+60 days'),
        'public'            => $faker->boolean(),
    ];
});

The top factory works no problem but the second one doesn't run at all cause my db seed to throw an error because its not populating the client_id which is a foreign key.

The only difference between the two models is that the client model doesn't use timestamps where as the shift model does. Other than that they are identical.

I will keep plugging away but any help to shed light on this would be greatly received.

Upvotes: 3

Views: 747

Answers (1)

Viral Solani
Viral Solani

Reputation: 840

When you add your own constructor, are you making sure to call parent::__construct() inside it?

Upvotes: 3

Related Questions