mercredi 16 mars 2022

Join one to many relationship tables and return all record using laravel eloquent

I have two tables users and posts. users has one to many relation with posts table. Post has 'type' column. This type may be sports,art, politics... etc.

users table - id, name, account_type, email

account_type may be active, test, blacklisted ... etc

posts table - id, user_id, name, type, date

Here I need to get all 'politics' posts of all 'active' players posted after a particular 'date'

How to get this using laravel eloquent way?

I have below function in User model class

public function post()
{
    return $this->hasMany( Post::class );
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire