You’re going to want the ‘many to many’ eloquent relationship.
https://laravel.com/docs/8.x/eloquent-relationships#many-to-many
Also checkout:
https://laravel.com/docs/8.x/eloquent-relationships#defining-relationships
In the Candidate model
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Candidate extends Model
{
/**
* The Availability that belong to the Candidate.
*/
public function availability()
{
return $this->belongsToMany('App\Models\Availability', 'availability_candidate', 'candidate_id', 'availability_id');
}
}
Then in the availability model
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Availability extends Model
{
/**
* The Candidate that belong to the Availability.
*/
public function candidate()
{
return $this->belongsToMany('App\Models\Candidate', 'availability_candidate', 'availability_id', 'candidate_id');
}
}
/**
* The Job Offer that belong to the Availability.
*/
public function jobs()
{
return $this->belongsToMany('App\Models\Jobs', 'availability_job_offer', 'availability_id', 'job_id');
}
}
Then in the Job model
class Availability extends Model
{
/**
* The Availability that belong to the Job.
*/
public function availability()
{
return $this->belongsToMany('App\Models\Availability', 'availability_job_offer', 'job_id', 'availability_id');
}
}
Finally to retrieve the jobs you would:
$jobs = $candidate->availability->jobs->where('key_on_jobs_table', $value)->get();
CLICK HERE to find out more related problems solutions.