🎉 سال نو، مهارت نو، مشاوره رایگان نقشه راه برنامه نویسی (آفر ویژه ثبت نام قبل از افزایش قیمت 🔥)
۰ ثانیه
۰ دقیقه
۰ ساعت
۱ mohammad dadkhah
عدم اجرای سرویس notification در پنل ایمیل
جامعه لاراول ایجاد شده در ۱۱ تیر ۱۴۰۰

 سلام به استاد گرامی و دوستان با تجربه

 این کد‌های notificationController ام

<?php
namespace App\Http\Controllers;
use App\Services\Notifications\counstants\EmailType;
use App\Services\Notifications\Notification;
use App\User;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
    public function email()
    {
        $users=User::all();
        $emailTypes=EmailType::tostring();
        return view('Notifications.Send-Email',compact('users','emailTypes'));
    }
    public function sendEmail(Request $request)
    {
        $request->validate([
            'user'=> 'integer | exists:users,id',
            'email_type'=>'integer'
        ]);
        $mailable=EmailType::toMail($request->email_type);
        $notification= resolve(Notification::class);
    $notification->sendEmail(User::find($request->user),new $mailable);
    }
}

این متود 

sendEmail() 

در خط آخر کد‌های بالا صدا زده می‌شود یعنی این متود همان متود

send()

ای است که در 

class EmailProvider 

است که صدا زده می‌شود؟

اگر همان متود باشد بنده به این ارور بر می‌خورم

TypeError
Argument 2 passed to App\Services\Notifications\Providers\EmailProvider::Send() must be an instance of App\Mail\TopicCreated, instance of App\Mail\ForgetPassword given, called in E:\laravel7.0\app\Services\Notifications\Notification.php on line 35 
EmailProvider.php
<?php
namespace  App\Services\Notifications\Providers;
use App\User;
use App\Mail\TopicCreated;
use Illuminate\Support\Facades\Mail;
class EmailProvider{
    public function Send(User $user, TopicCreated $topicCreated)
    {
        return Mail::to($user)->send($topicCreated);
    }
}
<?php
namespace App\Services\Notifications;
use App\Mail\TopicCreated;
use App\Services\Notifications\Providers\EmailProvider;
use App\Services\Notifications\Providers\SmsProvider;
use App\User;
use http\Client;
use Illuminate\Support\Facades\Mail;
use phpDocumentor\Reflection\Types\String_;
class Notification
{
/*    public function SendEmail(User $user, TopicCreated $topicCreated)
    {
        $emailProvider = new EmailProvider();
        dd($emailProvider);
        $emailProvider->Send($user, $topicCreated);
    }
    public function SendSms(User $user, String $text)
    {
        $smsProvider = new SmsProvider();
        $smsProvider->send($user, $text);
    }*/
    public function __call($method, $argument)
    {
        $provideName = __NAMESPACE__. '\Providers\' . substr($method, 4) . 'Provider';
        $providerInstance=new $provideName;
        $providerInstance->send(...$argument);
    }
}
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ForgetPassword 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->markdown('email.forget-password');
    }
}

لطفا راهنمایی کنید

سلام 

 

بله همان متد هستش 

 

ارور مشخص هستش،‌ به شما میگه که داخل کلاس EmailProvider انتظار داشته یک نمونه از کلاس TopicCreated بفرستید در صورتی که شما از کلاس ForgetPassword فرستادید،‌ شما باید به جای مشخص کردن کلاس TopicCreated بگید که من یک نمونه از کلاس Mailable میخوام .. دلیلش داخل این جلسه کامل توضیح داده شده.

 

https://7learn.ac/unit-core-part2

مهرداد سامی ۱۲ تیر ۱۴۰۰، ۰۹:۱۷