Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raviawasti's avatar

How to send name for subject_id from subject table in laravel?

I have subject table

Id =2 name:science

And i have Openings table where i save id =1 subject_id=2 title=science teacher job

$jobsdata = Openings::where('status',1)->orderBy('end_date','desc')->select('id','subject_id','title')->get();

I have set Relationship in Openings model

public function Subject() { return $this->belongsTo('App\Subject','subject'); }

I am getting data in view when i use relationship but, i want to know

How can i send science for subject_id field instead for id 2 from subject table in $jobsdata variable:-

0 likes
1 reply

Please or to participate in this conversation.