mercredi 8 juillet 2020

I am trying to get records from two tables with laravel using WhereAs

I am trying to get records of users from two tables..SALES TABLE & USER TABLE.

But from the SALES table, i want to get only sales of the current month for each of the user.

I have merged the tables already from the model, but when i try to get the record using this code it keeps pulling the sales for both current month and previous month from SALES table..

$myrecords = User::whereHas('sales', function($query) {
              $query->whereMonth('sales.created_at', Carbon::now()->month); 
}) 
->get();

Please what am i doing wrong here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire