I'm trying to fetch the column of a table and display it to the homepage. But I'm getting error exception saying object is not having company_name property. the laravel.log file error is as below-
[2020-10-05 16:53:04] local.ERROR: ErrorException: Undefined property: stdClass::$company_name in /opt/lampp/htdocs/gti/storage/framework/views/84eb893a069dfe58013e09b93b0adb7b017a6967.php:265 Stack trace: #0 /opt/lampp/htdocs/gti/storage/framework/views/84eb893a069dfe58013e09b93b0adb7b017a6967.php(265): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined prope...', '/opt/lampp/htdo...', 265, Array)
I'm using multiple tables hence the column value which I'm trying to fetch is from a join table. here is my controller:
public function opportunity($sector_id = '', $sub_sector_id = '')
{
if(empty($sector_id)){
$sector_id = 1;
}
$opportunity = '';
if($sector_id){
$sector = Sector::find($sector_id);
if(!empty($sub_sector_id)){
$opportunity = \DB::table('opportunities as p')
->select(\DB::raw('p.*'))
->join('companies','companies.id','=','p.company_id')
->join('users','users.id','=','companies.user_id')
->where('p.sector_id','=',$sector_id)
->where('p.sub_sector_id','=',$sub_sector_id)
->where('users.admin_approved','=',true)
->orderBy('created_at', 'DESC')
->get();
$opportunities = Opportunity::with(array('company' => function($query) use ($sector_id)
{
$query->where('sector_id',$sector_id);
}))
->select('opportunities.*')
->join('companies','companies.id','=','opportunities.company_id')
->join('users','users.id','=','companies.user_id')
->where('companies.sector_id',$sector_id)
->where('companies.sub_sector_id',$sub_sector_id)
->where('users.admin_approved','=',true)
->orderBy('created_at', 'DESC')
->get();
} else {
$opportunity = \DB::table('opportunities as p')
->select(\DB::raw('p.*'))
->join('companies','companies.id','=','p.company_id')
->join('users','users.id','=','companies.user_id')
// ->where('p.sector_id','=',$sector_id)
->where('users.admin_approved','=',true)
->orderBy('created_at', 'DESC')
->get();
$opportunities = Opportunity::with(array('company' => function($query) use ($sector_id)
{
$query->where('sector_id',$sector_id);
}))
->select('opportunities.*')
->join('companies','companies.id','=','opportunities.company_id')
->join('users','users.id','=','companies.user_id')
->where('companies.sector_id',$sector_id)
->where('users.admin_approved','=',true)
->orderBy('created_at', 'DESC')
->get();
}
}
$sub_sectors = SubSector::where('sector_id','=',$sector_id)->get();
$this->addAssets('opportunity');
$products = array();
return view('company.opportunity', compact('products','opportunities','sector_id','sub_sector_id','sector','sub_sectors'));
}
and here is how I'm fetching the values in homepage -
<section class="home_5th_section">
<div class="explore_opportunities_outer">
<div class="explore_opportunities_header">
<div class="">
<div class="title-page">explore opportunities</div>
<div class="b-line_new"></div>
</div>
<div class="view_all">
<div class="view_all_text">View All</div>
<span> > </span>
</div>
</div>
<div class="explore_opportunities_cards_sec">
@if(!empty($opportunities))
@foreach($opportunities as $key => $opportunity)
<div class="emerging_businesses_card">
<img src="" class="emerging_businesses_img">
<div class="emerging_businesses_heading">
</div>
<div class="emerging_businesses_desc">
</div>
<div class="emerging_businesses_view">
<img src="" class="">
<a href="/opportunity_details/"> <span class="">View</span></a>
</div>
</div>
@endforeach
@endif
" class="explore_opportunities_img">--}}
" class="">--}}
</div>
</div>
</section>
This is where I'm getting the error, Undefined property named company_name.
Unable to understand How? please help!
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3d10j8K
via IFTTT
Aucun commentaire:
Enregistrer un commentaire