اذهب إلى المحتوى
  • 0

check laravel jobs if it works

Mohammad Kiblawi

السؤال

لقد وصلت في المرحلة الاخيرة من المشروع و هي ارسال ايملات عن طريق  laravel jobs  و كما نعلم انها لا توجد في الدورات  

قمت بالبحث و وجدت بعص الامور التي ساعدتني بعض الشئ ولكن اريد ان اتأكد من الاكواد و اريد طريقة لاتأكد من ارسال البريد الالكتروني غير mailtrap  لان احتاج للاشتراك به

عموما هذه هي الاكواد 

كود في المتحكم

public function sendMails()
    {
        if (Auth::user()->role == 1) {
            $emails = Email::chunk(25, function ($email) {
                dispatch(new CompanyMail($email));
            });
            return 'emails will be sent in the background';
        } else {
            abort(403);
        }
    }

كود ال route

Route::get('/send-mails', [EmailController::class, 'sendMails']);

كود ال job

<?php

namespace App\Jobs;

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 CompanyMail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public $email;
    public function __construct($email)
    {
        $this->email = $email;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        foreach ($this->email as $email) {
            Mail::to($email->email)->send(new \App\Mail\CompanyMail());
        }
    }
}

كود ال mail

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class CompanyMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->subject('mail form Mohammad Kiblawi')->view('email.CompanyMail');
    }
}

كود ملفات التهجير

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateJobsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('jobs', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('queue')->index();
            $table->longText('payload');
            $table->unsignedTinyInteger('attempts');
            $table->unsignedInteger('reserved_at')->nullable();
            $table->unsignedInteger('available_at');
            $table->unsignedInteger('created_at');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('jobs');
    }
}

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

طالما انك في مرحلة التطوير محليا يفضل أن لا تعتمد على خدمات خارجية فهي ستعيق عملك وتزيد من مدة التطوير
يمكنك تخديم مشروعك باستخدام مخدم Laragon (أعتمده شخصيًا) يمكن تحميله من هنا

  • يوجد دليل هجرة من WAMP و XAMPP
  • يحتوي على ميزة Mail Catcher سيلتقط أي بريد الكتروني صادر من مشروعك محليا وينبهك ويقوم بحفظ النسخة المرسلة كما هي ضمن المجلد "laragon\bin\sendmail\output"

لا يبدو هناك مشاكل في الشيفرة، لكن بعد القيام بتنصيب المخدم والتجربة تابع شرح المشكلة (إن حدث أي مشاكل)

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...