Cannot access id on Eloquent model

401 Views Asked by At

I have an api endpoint that gives a web chat on my front end a list of online friends, however the user id is not included in my json, I would like to include the user_id in my json, but on my controller when I add the print_r like so...

public function index()
{
    $users = $this->friendService->getFriendsList();
    print_r($users);die();
    $json = Fractal::create()
        ->collection($users)
        ->transformWith(new FriendTransformer())
        ->toJson();

    return $json;
}

This the print_r output, how can I make the id accessible to my transformer?

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

There are 1 best solutions below

0
Cory Baumer On

OMG, I wasnt selecting it in the repository haha