ellajhonm's avatar

[Beginner] Sending SMS/Email notifications to all users efficiently

I have a 'New Job Alert' SMS and Email Notification that gets sent to all users, once the job post has been approved/added. As of now, this is how it's programmed:

public function approveJobPost(){
        // get job post id
        $pendingjob_id = request()->input('pendingjob_id');
        // get the jobpost
        $pendingjob = jobPost::find($pendingjob_id);
        // approve Job Post
        $pendingjob->update(array('is_approved' => 'Y','is_active' => 'Y'));

        // Message body
        $message = 'We have a new job available for you! CaRa Job Solutions is looking for a ' .$pendingjob->job_position.' around '.$pendingjob->client->address;
        // Formulate SMS Message
        $jobURL =  shortenURL('http://127.0.0.1/job/'.$pendingjob->slug);

        // dd("Orig: ".url('job/'.$pendingjob->slug)."New :".$jobURL);
        $txt_message = 'NEW JOB ALERT: '.$pendingjob->job_position.' | Link Here:'.$jobURL.' -CaRa Job Solutions';


        $jobData = [
            'body' => $message,
            'jobText' => 'Check Job Description',
            'url' => url('job/'.$pendingjob->slug),
            'thankyou' => 'Apply for a Job stress-free here at CaRa Job Solutions!'
        ];

        // notify all jobseeker
        $jobseekers = Jobseeker::all();
        // dd($jobseeker);
        // $jobseeker->notify(new NewJob($jobData));
        Notification::send($jobseekers, new NewJob($jobData));

        // Send text message to each user

        foreach($jobseekers as $jobseeker){
            $result = itexmo($jobseeker->contact_number,$txt_message);

            checkIfSent($result);
        }


        return back();
    }

This leads to a very long loading time, and I only have 10 users on my database. How can this be done more efficiently?

0 likes
1 reply

Please or to participate in this conversation.