May 16, 2015
0
Level 1
Laravel4.2 Query Problems between three tables
Database Tables are
employers
id | username | password
jobdetails
id | employer_id | title
empcompanies
id | employer_id | company_name
JobDetail.php // model
public function employer()
{
return $this->belongsTo('Employer');
}
EmpCompany.php // model
public function employer()
{
return $this->belongsTo('Employer');
}
Employer.php // model
public function empcompanies()
{
return $this->hasMany('EmpCompany');
}
public function jobdetails()
{
return $this->hasMany('JobDetail');
}
// Controller file
public function getApplyJobs($id)
{
$jobs = JobDetail::where('id', '=', $id)->get();
return View::make('home.apply')->with(compact('catjobs'));
}
// view.blade.php file
@foreach($jobs as $job)
@foreach($cat->empcompany() as $emp)
<td {{ $emp->company_name }}</td>
@endforeach
@endforeach
// here $id is jobdetails id, it works and fetch all data from jobdetails table. My Question is- How to show company_name from empcompanies. I tried those codes but it does not show the company_name, it shows blank. I am using Laravel4.2 Pls Help..
Please or to participate in this conversation.