Error Exception: Trying to get property of non-object - laravel

0

I need to get the ID and Name fields from my pivot table, I've tried this

public function Display(){

$langservice = new langService(); 

$musgroups=$langservice->getMusgroup(session()->get('lang_id'));

    foreach($musgroups as $musgroup1){
        foreach($musgroup1 as $musgroup){
            echo 'name:'+$musgroup->name;
        }
    }

But this error appears:

  

"Trying to get property of non-object".

I tried to do print_r($musgroups); but that brings the whole table in loop 12 times.

    
asked by Yandrakirtash 20.12.2018 в 16:27
source

1 answer

-1

I think you should go through all the data of your langService() model in this way

$langservice = new langService();
foreach( $langservice as $item){
  foreach($item->getMusgroup as $i)
  {
    $i->id;
    $i->name;
  }
}
return $langservice;
    
answered by 20.12.2018 в 16:48