当pivotloaded无法正常工作。始终返回空白
这是我的reportresource文件
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->cname,
'start' => $this->whenPivotLoaded('company_package', function () {
return $this->pivot->start_date;
}),
];
}
公司模型
class Company extends Model
{
//
public function packages(){
return $this->belongsToMany('App\Package')->withPivot('start_date');
}
}
软件包模型
class Package extends Model
{
public function companies(){
return $this->belongsToMany('App\Company')->withPivot('start_date');
}
}
控制器
return new ReportResource(Company::with('packages')->get());
我在做错了什么。请帮助
This is my ReportResource file
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->cname,
'start' => $this->whenPivotLoaded('company_package', function () {
return $this->pivot->start_date;
}),
];
}
Company Model
class Company extends Model
{
//
public function packages(){
return $this->belongsToMany('App\Package')->withPivot('start_date');
}
}
Package Model
class Package extends Model
{
public function companies(){
return $this->belongsToMany('App\Company')->withPivot('start_date');
}
}
Controller
return new ReportResource(Company::with('packages')->get());
What I am doing wrong .Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论