sllkevin's avatar

Tinker is returning only the Model namespace, without properties, only sometimes.

Why is this happening? See my first three queries that won't return any data, but using find() works great. I have cleared cache, routes, config. I've dumped autoload. I've downgraded versions. I've tried another project where it works as expected. If I add ->id to any of them, it works. Why??

> \Laravel\Cashier\Subscription::query()->where('id','=','3')->first()
= Laravel\Cashier\Subscription {#6527 …14}

> \Laravel\Cashier\Subscription::where('id',3)->get()->first()
= Laravel\Cashier\Subscription {#6954 …14}

> \Laravel\Cashier\Subscription::where('id',3)->first()               
= Laravel\Cashier\Subscription {#5841 …14}

> \Laravel\Cashier\Subscription::find(3)               
= Laravel\Cashier\Subscription {#6527
    id: 3,
    user_id: 1,
    type: "1",
    stripe_id: "3",
    stripe_status: "active",
    stripe_price: null,
    quantity: null,
    trial_ends_at: null,
    ends_at: "2024-08-14 00:47:03",
    created_at: null,
    updated_at: null,
    current_period_end: null,
    event_status: null,
    items: Illuminate\Database\Eloquent\Collection {#6525
      all: [],
    },
  }
0 likes
4 replies
sllkevin's avatar

In addition, Tinker is now also including hidden properties like password and remember_token when querying User. Same issue as above.

tykus's avatar
tykus
Best Answer
Level 104

This is an issue of PsySH which was subject of some discussing on X thread and in the package's Github issues relating to what PsySH is interpreting either as actions or inspections. The repo owner is

Seems not to be configurable yet, so the workaround is either (i) use the $_ approach after the query to see the verbose, expanded result:

> \Laravel\Cashier\Subscription::find(3)               
= Laravel\Cashier\Subscription {#5841 …14}

> $_
= Laravel\Cashier\Subscription {#5841
    id: 3,
    user_id: 1,
    type: "1",
    stripe_id: "3",
    stripe_status: "active",
    stripe_price: null,
    quantity: null,
    trial_ends_at: null,
    ends_at: "2024-08-14 00:47:03",
    created_at: null,
    updated_at: null,
    current_period_end: null,
    event_status: null,
    items: Illuminate\Database\Eloquent\Collection {#6525
      all: [],
    },
  }

or, (ii) lock you psysh to max. version 0.12.12

composer require psy/psysh:0.12.12

Hopefully this will be configurable soon

3 likes
sllkevin's avatar

Thank you so much for linking those references and providing an answer. I was going crazy trying to find all the changes I may have missed upgrading from Laravel 11 to 12.

tykus's avatar

No problem, please mark the thread solved if you are all set

Please or to participate in this conversation.