-
app/Http/Controllers/StaffController.php
Open in GitHubuse Illuminate\Http\Request; use App\Mail\StaffRegister; use Illuminate\Support\Facades\Mail; class StaffController extends Controller { // public function store(Request $request) { $attributes = $request->all(); $request->department_id != null && $attributes['department_id'] = $request->department_id['id']; $request->job_description_id != null && $attributes['job_description_id'] = $request->job_description_id['id']; $request->collar_type != null && $attributes['collar_type'] = $request->collar_type['value']; $request->manager_id != null && $attributes['manager_id'] = $request->manager_id['id']; $request->status != null && $attributes['status'] = $request->status['value']; $request->blood_group != null && $attributes['blood_group'] = $request->blood_group['value']; $attributes['creator_id'] = Auth::id(); $randomPassword = Str::random(8); $attributes['password'] = bcrypt($randomPassword); $mailData = []; $mailData['name'] = $request->name; $mailData['email'] = $request->email; $mailData['password'] = $randomPassword; User::create($attributes); $message = []; $message['type'] = 'success' ; $message['content'] = 'The staff has been successfully created. The staff created: '.$request->name ; Mail::to($request->email)->send(new StaffRegister($mailData)); return redirect()->route('staff.index') ->with('message', $message); } // }
-
app/Mail/StaffRegister.php
Open in GitHubuse Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; class StaffRegister extends Mailable { use Queueable, SerializesModels; public function __construct($mailData) { $this->mailData = $mailData; } public function build() { return $this->markdown('Mail.StaffRegister')->with('mailData', $this->mailData); } }