php artisan queue:table
.env
QUEUE_CONNECTION=database
php artisan make:job xxxxxx
<?php
namespace App\Jobs;
use App\Mail\NotiPayment;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
class SendPaymentNotiQueue implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $cc;
public $payment;
/**
* Create a new job instance.
*/
public function __construct($payment,$cc)
{
$this->payment = $payment;
$this->cc = $cc;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$email = new NotiPayment($this->payment);
Mail::to('ap@inyalakehotel.com')->cc($this->cc)->send($email);
}
}
php artisan make:mail xxxxx
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class NotiPayment extends Mailable
{
use Queueable, SerializesModels;
public $request;
/**
* Create a new message instance.
*/
public function __construct($request)
{
$this->request = $request;
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Noti Payment',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
view: 'email.notipayment',
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
create template for mail under view\email
Controller
public function store(Request $request)
{
$last= Payment::orderBy('id', 'DESC')->first();
if($last){
$last_id = $last->id + 200000 ;
}else{
$last_id = 200000;
}
$validateData = $request->validate([
'payment_date' => 'required',
'supplier' => 'required',
'currency'=>'required',
'amount'=>'required|numeric',
'ct'=>'required|numeric',
'ac_name'=>'required',
'settle_by'=>'required',
]);
if(!$request->ct==0){
$ct = $request->amount * $request->ct/100;
}else{
$ct = 0;
}
$payment = new Payment();
$payment->payment_date = $request->payment_date;
$payment->supplier = $request->supplier;
$payment->currency = $request->currency;
$payment->amount = $request->amount;
$payment->ct = $request->ct;
$payment->py_no = $last_id;
$payment->description = $request->description;
$payment->ac_name = $request->ac_name;
$payment->settle_by = $request->settle_by;
$payment->department_id = Auth::user()->department_id;
$payment->user_id = Auth::user()->id;
$payment->signature = Auth::user()->signature;
$payment->save();
$cc = Auth::user()->email;
SendPaymentNotiQueue::dispatch($payment,$cc);
return response()->json('Success');
}
* * * * * cd /var/www/html/ilhapp && php artisan queue:work --stop-when-empty
No comments:
Post a Comment