[英]belongsTo method returning null
我有兩個模型,一個叫Customer
第二個是Website
它們之間的關系是, Customer
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
用這個
$website = Website::find(1)->with('customermodel');
return dd($website->customermodel);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.