1
votes

I want to seed my db that shows me this error:

Call to undefined method Illuminate\Database\Query\Builder::passengers()

this is databse seeder:

public function run()
{
    // $this->call(UsersTableSeeder::class);
    factory(App\Airport::class, 5)->create();
    factory(App\Flight::class, 10)->create()->each(function ($flight) {
        factory(App\Customer::class, 100)->make()->each(function ($customer) use ($flight) {
            $flight->passengers()->save($customer);
        });
    });
}

Customer Model:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    public function Flights()
    {
        return $this->belongsToMany('App\Customer');
    }
}

Flight Model

class Flight extends Model
{
    //
    public function arrivalAirport(){
        return $this->belongsto('App\Airport','arrivalAirport_id');
    }
    public function departureAirport(){
        return $this->belongsto('App\Airport','departureAirport');
    }
    public function passenger(){
        return $this->belongsto('App\Customer','flight_customer');
    }
}

who know where this can come ?

1
Please can you show the code for your Flight model? - Rwd
@RossWilson Yes of course . i edited - Masoud

1 Answers

2
votes

You have used the singular in your model and trying to access the plural in the seeder.

class Flight extends Model
{
    public function passengers()
    {
        return $this->belongsto('App\Customer', 'flight_customer');
    }
}