【发布时间】:2018-11-13 13:29:21
【问题描述】:
下面是我的数据,我想用这个创建 API 资源-
array:1 [
0 => JobPosted {#2635
-id: 1
-jobTitle: "Business Development Executive"
-noOfPosition: 1
-experience: "2-5"
-jobLocation: "Mumbai"
-jobSkill: "Good communication skill, knowledge of Mandarin"
-jobDescription: "Good communication skill, knowledge of Mandarin"
-isClosed: false
-isActive: true
}
]
我在 laravel 中使用学说。 我的 JobResource 是
public function toArray($request){
return [
'jobTitle' => $this->getJobTitle(),
'noOfPosition' => $this->getNoOfPosition(),
'experience' => $this->getExperience(),
'jobLocation' => $this->getJobLocation(),
'jobSkills' => $this->getJobSkill(),
'jobDescription' => $this->getJobDescription()
];
}
而 JobResourceCollection 是
public function toArray($request){
return parent::toArray($request);
}
JobController 是这样的
public function getJobs(Request $request){
$jobs = $this->jobPostedService->getJobPosted($limit);
return response()->json(new JobResourceCollection($jobs), 200);
}
执行此操作后,我收到错误
Symfony\Component\Debug\Exception\FatalThrowableError (E_ERROR) 在数组上调用成员函数 first()
【问题讨论】:
-
请在jobpostedservice上使用getJobPosted方法