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.