我有一个 api 端点,它在我的前端为网络聊天提供了一个在线朋友列表,但是我的 json 中不包含用户 ID,我想在我的 json 中包含 user_id,但是当我添加时在我的控制器上print_r 像这样...
public function index()
{
$users = $this->friendService->getFriendsList();
print_r($users);die();
$json = Fractal::create()
->collection($users)
->transformWith(new FriendTransformer())
->toJson();
return $json;
}
这是 print_r 输出,我怎样才能让我的转换器可以访问 id?
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\User Object
(
[fillable:protected] => Array
(
[0] => name
[1] => email
[2] => password
)
[hidden:protected] => Array
(
[0] => password
[1] => remember_token
)
[appends:protected] => Array
(
[0] => photo_url
)
[connection:protected] => mysql
[table:protected] =>
[primaryKey:protected] => id
[keyType:protected] => int
[incrementing] => 1
[with:protected] => Array
(
)
[withCount:protected] => Array
(
)
[perPage:protected] => 15
[exists] => 1
[wasRecentlyCreated] =>
[attributes:protected] => Array
(
[name] => Cory Baumer
[last_activity_at] => 2018-10-19 20:38:09
)
[original:protected] => Array
(
[name] => Cory Baumer
[last_activity_at] => 2018-10-19 20:38:09
)
[changes:protected] => Array
(
)
[casts:protected] => Array
(
)
[dates:protected] => Array
(
)
[dateFormat:protected] =>
[dispatchesEvents:protected] => Array
(
)
[observables:protected] => Array
(
)
[relations:protected] => Array
(
)
[touches:protected] => Array
(
)
[timestamps] => 1
[visible:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
[rememberTokenName:protected] => remember_token
)
)
)