I want to do the following query with the ORM of Laravel:
public function rate_already_existing(Request $request)
{
$requests = DB::table('requests')
->join('feedbacks', 'requests.id', '=', 'feedbacks.request_id')
->select('requests.id')
->where('requests.id', '=', $request->input('assistanceRequestId'))
->get();
if(count($requests) > 0) {
return true;
}
}
The function should check if a request have already a feedback... in that case it returns true. The function above works, but I would like to do that function with the ORM to avoid too many rows and I tried the following:
public function rate_already_existing(Request $request)
{
$request_match = Req::find($request->input('assistanceRequestId'))->feedback->count();
if($request_match > 0) {
return true;
}
}
Unfortunately using the second function when the query have no rows the following error appears:
Call to a member function count() on null
Request model and feedback model have a one-to-one relationship.
Can help?