Here your code is correct but not completely
So I have modified it
Now you need to create one Job file using
php artisan make:job WelcomeMessage
and then run
php artisan migrate
to send the mail
use App\Job\WelcomeMessage;
public function store()
{
$customer = Customer::create($this->validatedData());
if ($customer) {
$allUser = Customer::where('id', '!=', $customer->id)->get();
$html = "Your html file with mail content";
$sub = "Welcome Mail";
foreach($allUser as $allUsers){
Mail::to($allUsers->email)->send(new WelcomeMessage($html,$sub));
}
}
return redirect('/customers');
}
If you run this command php artisan make:job WelcomeMessage
then it will create the page in the app\Job folder. Then paste the below code on that page.
<?php
namespace App\Emails;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class UserVerificationMail extends Mailable
{
use Queueable, SerializesModels;
public $subject;
public $file;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($file,$subject)
{
$this->subject = $subject;
$this->file = $file;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from(env('MAIL_FROM_ADDRESS'), env('APP_NAME'))
->subject($this->subject)
->markdown($this->file);
}
}
and then run php artisan queue:listen
This will work
Thank You