jeudi 9 juillet 2020

Get Data within two date range using subquery in laravel 5.1

I have 2 requirements:

  1. I have some users who need to pay some amount in monthly basis. I need to extract those information who paid/not within given date range. So in front-end i have two date input field (from-date to to-date). If the user select Jan-2020 - Jun-2020, it should get all the information within those date. I was able to get those values. But my requirement is, if a user did not pay in a month (suppose march-2020) it will return 0. Right now its only getting available data. I don't want to use any loop to get those data. I am looking for single query solution. Here is my query that i am using right now

         $paymentDetails = ReceivedUserPayment::select(
                 'id',
                 'user_id',
                 'received_amount_by_bank',
                 'received_time'
             )
             ->whereMonth('received_time', '>=', $dateFrom)
             ->whereMonth('received_time', '<=', $dateTo)
             ->orderBy('user_id')
             ->orderBy('received_time')
             ->get();
    
  2. I need to show some users information too in a table. So how should i group them with above information! My table structure is:

    Sl-(User Id)-(Full Name)-(Contact No)-(Month range)-Total

Here is the query from users table, (just in case if you need it):

        $studentIds = DB::table('users')
            ->select('id', 'full_name', 'contact_no')
            ->where('status', 1)
            ->get();

Is it possible to arrange this structure using only query! Or i need to loop through the data and make another array separately to structure my information!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire