0
我在數據庫中有一個通知表,並且還有一個用戶表。在通知表中,我有user_id,notific_user_id,post_id.I可以在Controller中打印$ r用戶變量,但可以訪問$ user->名字。laravel多維數組
這是控制器:
public function test()
{
$result=Notifications::where('user_id',Auth::user()->id)->get();
echo '<pre>';
foreach ($result as $result){
$user=User::where('id',$result->notific_user_id)->first()->get();
print_r($user);
}
}
這是一些輸出
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\User Object
(
[connection:protected] =>
[table:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[id] => 100000000
[created_at] => 2016-04-28 19:25:01
[updated_at] => 2016-05-10 05:03:22
[user_name] => 1
[first_name] => Tuhin
[last_name] => Hossain
[nick_name] =>
[email] => [email protected]
[password] => $2y$10$XtUWwJwVe2qf86CSUN6AkOkQlCWYq8/b3TrvBt2xuMlh4wTzRgxbG
[date_of_birth] => 2016-04-30
[gender] => 1
[remember_token] => a1U4V4rgJogw3hzXE9jJ8kHqtVrR5FkrMlvLEaRsC6qtmgX3LAbB3MkrZAgz
)
[original:protected] => Array
(
[id] => 100000000
[created_at] => 2016-04-28 19:25:01
[updated_at] => 2016-05-10 05:03:22
[user_name] => 1
[first_name] => Tuhin
[last_name] => Hossain
[nick_name] =>
[email] => [email protected]
[password] => $2y$10$XtUWwJwVe2qf86CSUN6AkOkQlCWYq8/b3TrvBt2xuMlh4wTzRgxbG
[date_of_birth] => 2016-04-30
[gender] => 1
[remember_token] => a1U4V4rgJogw3hzXE9jJ8kHqtVrR5FkrMlvLEaRsC6qtmgX3LAbB3MkrZAgz
)
[relations:protected] => Array
(
)
的現在,我怎麼能訪問名字,姓氏等? 我試過print_r($user->first_name);
但它沒有工作。請幫幫我。
哦謝謝它的工作原理 –