Support the ongoing development of Laravel.io →
Eloquent

I have a table to store all emails sended by laravel. I can fire events and store different information together with type (for example post, user, ...) and and id (id of the type). So when i send an email from post 4 i write into the storage a row with type="post" and type_id=4.

But how can i get this out of the database? I want to get all from email_storage (later with pagination) and if the type is post, i want to get from post with id=type_id... if it is user than get from user table with user_id=type_id ...

hope somebody can help me. My last code is:

public function post() { return $this->hasOne('App\Models\Post','id','type_id'); } $result = parent::with('post')->get();

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.