我在laravel 中为foreach() 提供的参数无效。我使用了 DB:: 和 Join 并在哪里给我
为 foreach() 提供的参数无效
控制器:
public function index()
{
$jobs =DB::table('jobs')->where('is_approved',true)
->join('countries','jobs.country_id','countries.id')
->join('job_types','jobs.job_type_id','job_types.id')
->select('jobs.*','countries.countryname','job_types.job_type')
->first();
$category=categories::all();
$countries=country::all();
return view('front.home.homeContant', compact('jobs','category','countries'));
}
看法
@forelse($jobs as $job)
<a href="{{url('/job-details',$job->id)}}" class="job-listing">
<!-- Job Listing Details -->
<div class="job-listing-details">
<!-- Logo -->
<div class="job-listing-company-logo">
<img src="{{ asset('front') }}/images/EETLogo.png" alt="">
</div>
<!-- Details -->
<div class="job-listing-description">
<h3 class="job-listing-title">{{ $job->title }}</h3>
<!-- Job Listing Footer -->
<div class="job-listing-footer">
<ul>
<li><i class="icon-material-outline-location-on"></i>{{ $job->countryname }}</li>
<li><i class="icon-material-outline-business-center"></i> {{ $job->Job_Type }}</li>
我使用了 Get() 但它给了我 ampty 数组
$jobs = DB::table('jobs')
->join('countries','jobs.country_id','countries.id')
->join('job_types','jobs.job_type_id','job_types.id')
->select('jobs.*','countries.countryname','job_types.job_type')
->where('is_approved',true)
->get();
当我删除
->join('job_types','jobs.job_type_id','job_types.id')
它运作良好
长风秋雁