Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

372
Views
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:

public function member()
    {
        return $this->belongsTo(Student::class, 'std_mbr_id');
    }

Member.php:

public function student()
    {
        return $this->hasOne(Student::class,'std_mbr_id');
    }

Then at the Controller, I added this:

public function index()
    {
        $student = new Student();
        $students = $student->searchStudents()->paginate(20);
        $custom = new Student();
        $customs = $custom->all();
        return view('admin.students.custom', compact('students','customs'));
    }

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

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

$customs->find($student->mbr_id) ? $customs->find($student->mbr_id)->created_at : 'not found';
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!