I need help defining Laravel Eloquent relationships

The two models:

class Event extends Model
{  // serves the same role as Post 
    public function memoryof()
    {  
        return $this->hasMany(MemoryOf::class);
    }
}



class MemoryOf extends Model
{  // serves the same role as comments
    public function event()
    {
          return $this->belongsTo(Event::class);
    }
    
}

I retrieve the data like this:

$events=Event::with('memories')->get()->sortByDesc('created_at');

This SHOULD give me a collection. Instead it gives:

“Property [memoryof] does not exist on this collection instance.”

Please help me to fix this so that I get a collection.

Answer

Please try this

$events = Event::with('memoryof')->get()->sortByDesc('created_at');
dd($events)