Answer the question
In order to leave comments, you need to log in
Why does belongsToMany always return 1?
You need to check if the user applied for the job. But relation always returns 1. What is the problem?
public function applied($job_id)
{
$this->belongsToMany('App\Job', 'job_applies');
}
{{count($user->applied($job->id))}}
Answer the question
In order to leave comments, you need to log in
First, you declared a parameter $job_id
but you don't use it anywhere.
Secondly,
// User model
public function jobs()
{
return $this->belongsToMany('App\Job', 'job_applies');
}
public function applied($job_id)
{
return $this->jobs()->where('job_id', $job_id)->count() > 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question