i have follwing data in my array
Array
(
[id] => 11
[username] => username
[avatar] => uploads/5.jpg
[email] => username@example.com
[designation] => TT
[supervisor] => Array
(
[id] => 3
[username] => alex
[avatar] => uploads/3.jpg
[email] => alex@example.com
[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
)
i am trying to access supervisor username but it always throw an error like
Trying to get property of non-object in view
i have tried to access that in following method but it doesn't work
$single_view_user->supervisor->username
$single_view_user['supervisor']->username
$single_view_user['supervisor']['username']
can any one tell what i am doing wrong ? thank you
update
in my view for printing purpose i am using
{{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>
and in my controller
$single_view_user = User::where('id',$id)->with('Supervisor')->first();
return view('admin/single_view_user',['single_view_user'=>$single_view_user]);
Update 2
@foreach($single_view_user as $val)
{{print_r($val) }}
@endforeach
ouput will be like
11 11 11 1