Hi Devs, In Laravel when accessing a relationship property we not sure whether the relationship data exists. but what if not exists those times we get the following Warning; Consider the Below code $user = User::findOrFail(1); $subscription = $user->subscription->created_at; Enter fullscreen mode PHP Notice: Trying to get property 'created_at' of non-object in /Users/benittoraj/code/laravel/mas-laraveleval()'d code on line

Do You know there is another way of handling this using object_get helper function $subscriptionCreatedAt = object_get($user, 'subscription.created_at); Enter fullscreen mode The Nice thing about object_get helper function is we can access the relationship relation property using dot syntax.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners