I have field names in my model that are numbers (I don't have control over it's names). When I try to get values from my model I get an Exception, before having those fields everything was fine
This worked fine till the number field were added.
Model::find($id)->name;
I get Trying to get property of non-object
I tried to hide them from my JSON with the protected hidden
array but neither '0'
, 0
or '{0}'
seems to work.
This is the error
{
"errors": "Sorry, something went wrong.",
"exception": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
"message": "Uncaught exception 'ErrorException' with message 'Trying to get property of non-object' in /home/david/workspace/papw2/jukebox/api/app/AlbumComment.php:18\nStack trace:\n#0 /home/david/workspace/papw2/jukebox/api/app/AlbumComment.php(18): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Trying to get p...', '/home/david/wor...', 18, Array)\n#1 /home/david/workspace/papw2/jukebox/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2669): App\\AlbumComment->getUserAttribute(NULL)\n#2 /home/david/workspace/papw2/jukebox/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2681): Illuminate\\Database\\Eloquent\\Model->mutateAttribute('user', NULL)\n#3 /home/david/workspace/papw2/jukebox/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2435): Illuminate\\Database\\Eloquent\\Model->mutateAttributeForArray('user', NULL)\n#4 /home/david/workspace/papw2/jukebox/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2379): Illuminate\\Dat",
"trace": []
}
What is the correct syntax for this?