Level 32
In your JobController
public function show($id){
$workRecord = WorkRecord::findOrFail($id);
$jobsRelated = $workRecord->jobs();
}
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello! I have 3 models and the related tables in my database
User (user_id)
Work Record (work_id, user_id, notes)
Job (job_id, work_id, description)
What I want to be able to do is visit "http://example.com/WorkRecords/{Work Record Id}/jobs" and then display all jobs/CRUD linked to the work record.
So far I can Create and Update Work Records linked to the user, but I am not too sure what happens next. I have
Route::resource('work-record/{id}/job', 'JobController');
Route::resource('work-record', 'WorkRecordController');
I am not too sure what to put in the JobController to get the work-record id and link into the jobs. Am I heading in the right direction?
Thanks in advance.
In your JobController
public function show($id){
$workRecord = WorkRecord::findOrFail($id);
$jobsRelated = $workRecord->jobs();
}
Please or to participate in this conversation.