Axios / Controller return empty object? Check protected $dates, deleted_at
I'm not sure if I missed the message on this one but wanted to share with others. Been working on non-working controller methods returning records in the standard Response::json way back through Axios. Using standard resourceful routing, my index method works to get all records while the show method pulling one record does not. The issue appears to be an empty deleted_at field in protected $dates.
So, to be clear, 1) I'm using SoftDeletes on the model, 2) My table is seeded properly, 3) I had a protected $dates field on the model as protected $dates = [''] (meaning wrong / empty array, wrong), 4) Using resourceful routing through L 5.4 api.php, 5) Controller index method successfully pulls all records and passes back using Axios, 6) show method using injection FAILS. 7) I'm using getRouteKeyName on the model to bind to a slug.
By accidentally omitting 'deleted_at' in protected $dates, I was getting an empty object back via the Api. Couldn't figure this out, then bam neglected to list deleted_at in protected dates. Put that in, and controller easily found the resource record.
I'm sure everyone already knows this, but perhaps will help someone! can't get the record via show method and Axios? Check that your protected $dates array!
Had this: protected $dates = [''] //wrong Corrected to ['deleted_at'] (as would be normal) and all of a sudden Eloquent popped to life!
Please or to participate in this conversation.