🎉 سال نو، مهارت نو، مشاوره رایگان نقشه راه برنامه نویسی (آفر ویژه ثبت نام قبل از افزایش قیمت 🔥)
۰ ثانیه
۰ دقیقه
۰ ساعت
۲ Afravi Mostafa
topic created error
جامعه لاراول ایجاد شده در ۰۴ دی ۱۴۰۱
error
App\\Services\\Notification\\Notification::sendEmail(): Argument #2 ($mailable) must be of type Illuminate\\support\\Mailable, App\\Mail\\TopicCreated given, called in C:\\Users\\afrav\\Notification\\routes\\web.php on line 23
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 TopicCreated extends Mailable
{
    use Queueable, SerializesModels;
    private $first_name;
    private $last_name;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->first_name = 'mosy';
        $this->last_name = ' afravi';
    }
    /**
     * Get the message envelope.
     *
     * @return \\Illuminate\\Mail\\Mailables\\Envelope
     */
    public function envelope()
    {
        return new Envelope(
            subject: 'Topic Created',
        );
    }
    /**
     * Get the message content definition.
     *
     * @return \\Illuminate\\Mail\\Mailables\\Content
     */
    public function content()
    {
        return new Content(
            view:'emails.topic-created',
            with:([
                'full_name'=>$this->first_name . $this->last_name
            ]),
        );
    }
    /**
     * Get the attachments for the message.
     *
     * @return array
     */
    public function attachments()
    {
        return [];
    }
}
/////////////////////////////////////

use App\\Services\\Notification\\Notification;
use Illuminate\\Support\\Facades\\Route;
use App\\Mail\\TopicCreated;
use App\\Models\\User;
use App\\Mail\\UserRegistered;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
    $notification = resolve(Notification::class);
    $notification->sendEmail(User::find(1) , new TopicCreated);
    
});

سلام مصطفی عزیز

تایپ ورودی فانکشن sendemail رو تغییر بدید و داخل متد چک کنید به شکل زیر:34ae-Screenshot_۲۰۲۲-۱۲-۲۵-۲۱-۴۹-۱۹-۵۱۹-edit_com.android.chrome.jpg

بعد از حذف تایپ داخل فانکشن کد زیر رو بزنید

if($mailable instanceof Mailable) {
    return Mail::to($user)->send($mailable);
}
بهترین پاسخ
احمدرضا فاطمی کیا ۰۴ دی ۱۴۰۱، ۱۸:۲۸

دلیل ارور اختلاف ورژن لاراول من و تدریس هست؟

2_ ایمیل ارسال نشد؟

Afravi Mostafa ۰۴ دی ۱۴۰۱، ۱۸:۴۳