시도를 다음과 같이 두 번째 인수로 USER_ID를 추가하여 관계 (사용자 테이블)을 참조하기 :
class Order extends Eloquent {
protected $table = 'orders';
public function customer() {
return $this->belongsTo('Customer');
public function location() {
return $this->customer()->location(); // this does not work
}
}
class Customer extends Eloquent {
protected $table = 'customers';
public function user() {
return $this->belongsTo('User');
}
public function orders() {
return $this->hasMany('Order');
}
public function location() {
return $this->user()->location();
// return $this->user(); // WORKS!!
}
}
class User extends Eloquent {
protected $table = 'users';
public function locations() {
return $this->hasMany('Location');
}
public function location() {
return $this->locations()->first();
}
}
나는 결국이 작업을 수행 할 수
public function user() {
return $this->belongsTo('User',"user_id");
}
은 아마 당신은 전화 id 필드가 다르지만 내가 무슨 뜻인지 알 것입니다.
이 기본값이 아닙니까? –
글쎄, 당신이 다른 모델 이름을 당신의 이름, 당신은 id에 대해 명시해야합니다. – carousel
메소드 이름은 모델과 다릅니다. –