繁体   English   中英

当方法返回null

[英]belongsTo method returning null

我有两个模型,一个叫Customer第二个是Website

它们之间的关系是, Customer WebsiteWebsite属于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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM