I got an error when I try to retrieve many to many relationship data in Laravel. The message of error is
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select * from
jobswhere (not exists (select * fromjob_typesinner joinjob_types_jobsonjob_types.id=job_types_jobs.job_types_idwherejobs.id=job_types_jobs.jobs_idandjob_types.deleted_atis null) or exists (select * fromjob_typesinner joinjob_types_jobsonjob_types.id=job_types_jobs.job_types_idwherejobs.id=job_types_jobs.jobs_idandid= 3 andjob_types.deleted_atis null) andnameLIKE %%) andjobs.deleted_atis null)
JobTypes.php
public function jobs() // children
{
// one type of job has many jobs
return $this->belongsToMany('App\Jobs'); // id refer to jobs.id
}
Jobs.php
public function job_types() // parent
{
// one job only belongs to one type of job
return $this->belongsToMany('App\jobTypes');
}
JobTypeController.php
public function assignJob($id)
{
$jobType = \App\JobTypes::withTrashed()->find($id);
$jobs = $jobType->jobs;
return view('job-types.assign-job', compact(['jobType', 'jobs']));
}
View
<label for="name">Job</label>
<select selected="selected" multiple class="form-control " name="jobs[]" id="jobs" class="jobs"></select>
<div class="invalid-feedback">
</div>
via Chebli Mohamed

Aucun commentaire:
Enregistrer un commentaire