我有两个名为Customer
的模型,第二个是Website
他们之间的关系是Customer
hasMany Website
而Website
属于Customer
这就是我这样做的方式
class Website extends \Eloquent {
use SubscriptionBillableTrait;
protected $fillable = [];
protected $guarded = ['id'];
public function customermodel()
{
// Return an Eloquent relationship.
return $this->belongsTo('Customer')
}
}
Customer
型号
use Mmanos\Billing\CustomerBillableTrait;
class Customer extends \Eloquent {
use CustomerBillableTrait;
protected $fillable = [];
protected $guarded = ['id'];
public function websites() {
return $this->hasMany('Website');
}
}
当我尝试通过此类关系访问Customer
$website = Website::find(1);
return dd($website->customermodel);
返回null
注意:我使用的是Laravel 4
答案 0 :(得分:0)
使用此
$website = Website::find(1)->with('customermodel');
return dd($website->customermodel);