无法访问口才模型上的ID

时间:2018-10-19 20:47:38

标签: laravel eloquent thephpleague-fractal

我有一个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
                )

        )

)

1 个答案:

答案 0 :(得分:0)

OMG,我不是在存储库中选择它的哈哈