有问题传递数组来查看

时间:2016-04-04 23:21:23

标签: php laravel

在我的控制器中

$streets_mix= DB::table('m_Menu as m')->select('m_Menu_name as name','m_Menu_description as desc','m_Menu_price as price','R.rs_Rest_name as restau')->join('Restaurant as R',function($join){
                   $join->on('R.rs_Rest_id','=','m.rs_Rest_id')->where('R.s_Street_name', '=',$this->s_name);
                })->get();
 return View::make('pages.menu')->with('details',$streets_mix);

在我看来我有

 @foreach($details as $value)
     $value['name'];
     $value['desc'];
 @endforeach

我的错误讯息 e35c8c51c47b58836bbdd69ba22fc85e第28行FatalErrorException: 不能使用stdClass类型的对象作为数组

如果我这样做

var_dump($streets_mix);
array(2) { [0]=> object(stdClass)#163 (4) { ["name"]=> string(3) "eru" ["desc"]=> string(81) "made with water leaf and oilwith litle salt.Can be eaten with garri n water fufu" ["price"]=> string(4) "1000" ["restau"]=> string(11) "Mouth power" } [1]=> object(stdClass)#164 (4) { ["name"]=> string(3) "eru" ["desc"]=> string(81) "made with water leaf and oilwith litle salt.Can be eaten with garri n water fufu" ["price"]=> string(4) "1000" ["restau"]=> string(11) "Mouth power"

1 个答案:

答案 0 :(得分:2)

视图获取一组对象。

像访问对象一样访问该属性。

@foreach($details as $value)
     $value->name;
     $value->desc;
@endforeach