دوستان من طبق فیلم رفتم جلو ولی این ارور رو میده که خودمون تعیین کردیم
Mailable class does not exist
کد فایل EmailType
<?php
namespace App\Service\Notifaction\constants;
use App\Mail\ForgetPassword;
use App\Mail\TopicCreated;
use App\Mail\UserRegistered;
use App\User;
class EmailType{
const USER_REGISTERED = 1;
const TOPIC_CREATED = 2;
const FORGET_PASSWORD = 3;
public static function toString(){
return [
self::USER_REGISTERED => 'ثبت نام کاربر',
self::TOPIC_CREATED => 'ایجاد مقاله جدید',
self::FORGET_PASSWORD => 'فراموشی رمز عبور',
];
}
public static function toMail($type)
{
try {
return [
self::USER_REGISTERED => UserRegistered::class,
self::TOPIC_CREATED => TopicCreated::class,
self::FORGET_PASSWORD => ForgetPassword::class
][$type];
} catch (\Throwable $th) {
throw new \InvalidArgumentException('Mailable class does not exist');
}
}
}
کد NotifactionController
<?php
namespace App\Http\Controllers;
use App\Service\Notifaction\constants\EmailType;
use App\Service\Notifaction\Notifaction;
use App\User;
use Illuminate\Http\Request;
class NotifactionController extends Controller
{
public function email(){
$users = User::all();
$emailType = EmailType::toString();
return view('notifaction.send-email' , compact('users' , 'emailType'));
}
public function sendEmail(Request $request){
$request->validate([
'user' => 'integer | exists:users,id',
'email_type' => 'integer'
]);
$notifaction = resolve(Notifaction::class);
$maillable = EmailType::toMail($request->email_type);
$notifaction->sendEmail(User::find($request->user) , new $maillable);
}
}