在laravel通知中获取列内的数据

时间:2018-08-08 06:58:33

标签: arrays laravel pusher

在我的控制器中使用DD,我得到了这个结果。现在,我想在列名称数据中获得“ id”:45 enter image description here

控制器:

fd35e0f3-a162-48f9-9d69-b39c601513a2: Core.ItemService - Calling method Get with parameters 1... 
fd35e0f3-a162-48f9-9d69-b39c601513a2: Core.Repositories.ItemRepository - Calling method Get with parameters 1... 
fd35e0f3-a162-48f9-9d69-b39c601513a2: Done Core.Repositories.ItemRepository - Get: result was Id is 1, SomeProperty is Property1, AnotherProperty is Another1
fd35e0f3-a162-48f9-9d69-b39c601513a2: Done Core.ItemService - Get: result was Id is 1, SomeProperty is Property1, AnotherProperty is Another1
1ed6bfd7-f786-4397-905e-6ba7027bdd55: Core.ItemService - Calling method Get with parameters 5... 
1ed6bfd7-f786-4397-905e-6ba7027bdd55: Core.Repositories.ItemRepository - Calling method Get with parameters 5... 
1ed6bfd7-f786-4397-905e-6ba7027bdd55: Done Core.Repositories.ItemRepository - Get: result was Id is 5, SomeProperty is Property5, AnotherProperty is Another5
1ed6bfd7-f786-4397-905e-6ba7027bdd55: Done Core.ItemService - Get: result was Id is 5, SomeProperty is Property5, AnotherProperty is Another5

3 个答案:

答案 0 :(得分:3)

Id是唯一的,请使用first代替get

 $test = DB::table('notifications')->where('id', $id)->first();
 $dataId = $test->data->id;
 //or $dataId = json_decode($test->data)->id;

答案 1 :(得分:0)

use App\Notification; 

$test = Notification::where('id', $id)->first();
$dataId = $test->id;
dd($dataId);

答案 2 :(得分:0)

仅在下面一行:

$notifications = auth()->user()->notifications->pluck('data')->flatten(1);