Skip to content
Advertisement

Laravel 5.8: Weird Error Trying to get property ‘created_at’ of non-object

I’m using Laravel 5.8 to develop my project and in this project, I have a OneToMany relationship between Member Model & Student Model like this:

Student.php:

JavaScript

Member.php:

JavaScript

Then at the Controller, I added this:

JavaScript

Now at the view I want to get created_at timestamp like this:

$customs->find($student->mbr_id)->created_at

But this will return this error:

Trying to get property ‘created_at’ of non-object

However when I do dd($customs->find($student->mbr_id)), I can properly get the timestamps:

enter image description here

So how to access the created_at timestamp in this situation?


UPDATE #1:

Result of {{ dd($customs->find($student->mbr_id)->created_at ) }}:

enter image description here

Advertisement

Answer

First check if $customs->find($student->mbr_id) returns something:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement