How to send report in in scheduled time

Posted 1 week ago by PetroGromovo

Hallo, In laravel 5.8 I have a report with a button “Send Email” by clicking on this button ajax request is run, with content of a report in “report_html” var to control like:

    public function sentReportEmailContent()
    {
        $request= request();
        $requestData= $request->all();

        $report_html= $requestData['report_html'];

        $loggedUser= Auth::user();

        $reportAvailableSpacesByZonesAcceptorsArray = config('app.reportAvailableSpacesByZonesAcceptorsArray', []);
        $site_name                                  = config('app.name', '');
        if ( count($reportAvailableSpacesByZonesAcceptorsArray) == 0 ) {
            return response()->json(['error_code' => 1, 'message' => 'There are no receiver emails specified !'], HTTP_RESPONSE_INTERNAL_SERVER_ERROR);
        }

        $to= $reportAvailableSpacesByZonesAcceptorsArray[0];
        $subject= 'Available Spaces By Zones report was sent at ' . $site_name;
        $additiveVars= [ 'html'=> $report_html ];

        unset($reportAvailableSpacesByZonesAcceptorsArray[0]);
        $cc= $reportAvailableSpacesByZonesAcceptorsArray;
        \Mail::to($to)->send( new SendgridMail( 'emailContainer', $to, $cc, $subject , $additiveVars ) );

        return response()->json(['error_code' => 0, 'message' => '', 'user'=> $loggedUser->id], HTTP_RESPONSE_OK);
    }

and with Sendgrid service report is sent to users defined in config ok.

Now I need to run this report and send email to recievers in scheduler.

I created a new command :

php artisan make:command reportAvailableSpacesByZones  --command=report:available-spaces-by-zones
which has handle method:
    public function handle()
    {
        \Log::info( 'Report run # ' . time()  );
    }

which is triggered in scheduled time. But how can I run my report and sent it's content like it is done manually ?

Thanks!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.