i want to show all of the job posts of a company. i have defined the relationship models.
class Company extends Model
{
//
protected $fillable = [
'user_id',
'name',
'company_size',
'slogan',
'website',
'logo',
'message_title',
'message_content',
'main_photo',
'about_us',
'why_us',
'recruiting_steps',
'address',
'email',
'phone_number',
'location',
];
public function Users(){
return $this->hasMany('App\Models\User');
}
public function job_posts(){
return $this->hasMany('App\Models\JobPost', 'company_id');
}
}
job posts model:
class JobPost extends Model
{
protected $table = 'job_posts';
protected $fillable = [
'company_id',
'user_id',
'title',
'summary',
'description',
'requirements',
'benefits',
'approval',
'location',
'publish_date',
'expiration_date'
];
public function user()
{
return $this->belongsTo('App\Models\User');
}
public function company()
{
return $this->belongsTo('App\Models\Company', 'company_id');
}
public function cv_folders()
{
return $this->hasMany('App\Models\CvFolder');
}
}
my companies controller show method
public function show(Company $company)
{
//
$company = Company::find($company->id);
$JobPosts = $company->JobPosts;
return view('Companies.show', [
'company' => $company,
'JobPosts' => $JobPosts,
]);
}
my companies view:
@foreach($JobPosts as $jobPost)
<div class="col-md-12">
<div class="box box-default box-solid">
<div class="box-header with-border">
<h3 class="box-title"></h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i
class="fa fa-minus"></i>
</button>
</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body" style="">
The body of the box
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
@endforeach
but i get the error
"Invalid argument supplied for foreach() (View: C:\xampp\htdocs\hrlead\resources\views\companies\show.blade.php)" please help me
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire