Passing model object from controller to view which contains inner join in laravel -


according https://laravel.com/docs/5.2/queries#joins documentation, i've done joining in controller file.

but want fetch data object in views file. shows errors!

my pagescontroller file

$storages=db::table('storages')                 ->join('dealers_of_distributors', 'storages.distributorid', '=', 'dealers_of_distributors.distributorid')                 ->select('storages.*', 'dealers_of_distributors.dealerid')                 ->get();  return views('pages.home')->withstorages($storages); 

i can not fetch data storages object in views file

my views file

@if($storages->isempty())     <li>no storage!</li> @else     @foreach($storages $stg)         <li>{{ $stg->name }}</li>         <li>{{ $stg->distributor->name }}</li> //i've done implemented distributor() function inside storage moel         @foreach($stg->dealerid $dealer) //multiple dealers 1 storage             <li>{{ $dealerid }}</li>         @endforeach     @endforeach @endif 

the first error i'm seeing:

call member function isempty() on non-object 

how can fix ?

we use db::table('table_name')->get(); return array not object. if want have model object, should use storage::get();


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -