我在陣列試圖獲取非對象視圖中的屬性?
Array
(
[id] => 11
[username] => username
[avatar] => uploads/5.jpg
[email] => [email protected]
[designation] => TT
[supervisor] => Array
(
[id] => 3
[username] => alex
[avatar] => uploads/3.jpg
[email] => [email protected]
[designation] => ADM
[supervisor] =>
[created_at] => 2015-09-10 03:58:46
[updated_at] => 2015-09-10 03:58:46
)
[created_at] => 2015-09-10 04:29:47
[updated_at] => 2015-09-10 04:29:47
)
我試圖訪問主管的用戶名,但它總是拋出這樣的錯誤
Trying to get property of non-object in view
我曾經試圖訪問在以下方法follwing的數據,但它不」 t工作
$single_view_user->supervisor->username
$single_view_user['supervisor']->username
$single_view_user['supervisor']['username']
可以任何一個告訴我做錯了什麼? 謝謝
更新
在我打印的目的視圖我使用
{{print_r($single_view_user->toArray())}}
<tr class="active">
<th>Profile Picture</th>
<td><img src="{{asset($single_view_user->avatar)}}" ></td>
</tr>
<tr class="active">
<th>Username </th>
<td>{{$single_view_user->username}}</td>
</tr>
<tr class="active">
<th>email</th>
<td>{{$single_view_user->email}}</td>
</tr>
<tr class="active">
<th >Designation</th>
<td>{{$single_view_user->designation}}</td>
</tr>
<tr class="active">
<th>supervisor</th>
<?php $single_view_user['supervisor']['username']; ?>
<td>{{ $single_view_user['supervisor']->username}}</td>
</tr>
,並在我的控制器
$single_view_user = User::where('id',$id)->with('Supervisor')->first();
return view('admin/single_view_user',['single_view_user'=>$single_view_user]);
更新2
@foreach($single_view_user as $val)
{{print_r($val) }}
@endforeach
輸出中會像
11 11 11 1
嘗試簡單地使用'$ single_view_user [ '監督員'] [ 'username']' –
嗨,你能告訴我們你如何傳遞對象來查看?這很重要。 – Extrakun
@vision錯誤? – aldrin27