I tried to use withCount() method just like the documentation and always i get this error : Call to undefined method Illuminate\Database\Query\Builder::withCount()
public function index($id)
{
$data = \App\Institute::find($id);
if(!$data)
return response()->json(['message' => trans('system.notFound')])->setStatusCode(404);
$users = \App\MainArea::withCount('institute')->where('institute_id',$id)->get();
return $users;
}
any suggestion ?