After upgrading to Laravel 8 from Laravel 5.8, I am unable to use just one of my factories in tinker using the following command:
Route::factory()->make();
This works no problem for my other factories, and I have checked everything looks correct.
This command returns the error:
PHP Notice: Undefined offset: 0 in
/vendor/laravel/framework/src/Illuminate/Routing/Router.php on line 1252
InvalidArgumentException with message 'Attribute [factory] does not exist.'
My route model -
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Route extends Model
{
use HasFactory;
public function runs()
{
return $this->hasMany('App\Models\Run');
} //
}
My factory -
namespace Database\Factories;
use App\Models\Route;
use Illuminate\Database\Eloquent\Factories\Factory;
class RouteFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Route::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'destination' => $this->faker->city,
'miles' => rand(15,90),
'name' => $this->faker->word,
'type' =>$this->faker->randomElement($array = array('Blah', 'Blah1', 'Blah2', 'Blah3')),
'owner' => $this->faker->name,
];
}
}
Strangely (to me at least), I can use my db seeder and it works fine. This is using:
$routes = Route::factory()->count(50)->create();
Any suggestions would be greatly appreciated!