我想播发显示此错误的数据库:
调用未定义的方法Illuminate \ Database \ Query \ Builder :: passengers()
这是数据库种子:
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);
});
});
}
namespace App;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
public function Flights()
{
return $this->belongsToMany('App\Customer');
}
}
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');
}
}
谁知道这能到哪里来?
答案 0 :(得分:2)
您已在模型中使用了单数,并尝试在播种器中使用复数。
class Flight extends Model
{
public function passengers()
{
return $this->belongsto('App\Customer', 'flight_customer');
}
}