Fab*_*ioG 0 php laravel eloquent laravel-5
我知道以前曾经问过这个问题,但根据我的情况,我找不到一个有效的答案.
目前我有两个型号.App\JobStatus App\Customer
在模型App\JobStatus我有这个:
public function customer()
{
return $this->belongsTo('App\Customer');
}
Run Code Online (Sandbox Code Playgroud)
在模型App\Customer我有这个:
public function jobs()
{
return $this->hasMany('App\JobStatus', 'customer_id');
}
Run Code Online (Sandbox Code Playgroud)
'customer_id'是外键.然后我尝试从我的控制器中的Jobstatus访问客户,如下所示:
$testMePlease = JobStatus::first()->where('qb', '=', 1);
$testMePlease->customer;
Run Code Online (Sandbox Code Playgroud)
我曾尝试过这个.把它放在foreach循环中.我也试过$ testMePlease-> customer-> customer_name.Customer_name是表中的一列,我得到了同样的错误:"Undefined property:Illuminate\Database\Eloquent\Builder :: $ customer"
我有什么想法我做错了吗?
小智 5
试着改变
$testMePlease = JobStatus::first()->where('qb', '=', 1);
Run Code Online (Sandbox Code Playgroud)
至
$testMePlease = JobStatus::where('qb', '=', 1)->first();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39 次 |
| 最近记录: |