jeudi 10 septembre 2020

Get associated record based on condition from second table using relation in Laravel

I have a user table structure like :

id | user_id | name

second table is booking table

id |  user_id  |  category_id  | booking_amt

Now i want to get all the data from booking table where user_id and category_id gets matched.

I'm trying something like this:

I'm getting all data from users table:

 $query = User::where(['active'=>1])->get();    

Booking Model:

public function getAssociatedDealer()
{
    return $this->hasMany('App\Models\Booking', 'user_id', 'category_id');
} 


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire