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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners