-
app/Mail/Company/InviteEmployeeToBecomeUserMail.php
Open in GitHubuse Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use App\Models\Company\Employee; use Illuminate\Queue\SerializesModels; class InviteEmployeeToBecomeUserMail extends Mailable { use Queueable, SerializesModels; public $employee; public function __construct(Employee $employee) { $this->employee = $employee; } public function build() { return $this->subject(trans('mail.invite_employee_to_become_user')) ->markdown('emails.company.invitation'); } }
-
app/Services/Company/Adminland/Employee/InviteEmployeeToBecomeUser.php
Open in GitHubuse App\Services\BaseService; use App\Models\Company\Employee; use Illuminate\Support\Facades\Mail; use App\Mail\Company\InviteEmployeeToBecomeUserMail; class InviteEmployeeToBecomeUser extends BaseService { // public function execute(array $data): Employee { $this->validateRules($data); $this->author($data['author_id']) ->inCompany($data['company_id']) ->asAtLeastHR() ->canExecuteService(); $employee = $this->validateEmployeeBelongsToCompany($data); // } private function inviteEmployee(Employee $employee): void { if ($employee->invitation_used_at) { throw new UserAlreadyInvitedException(); } Employee::where('id', $employee->id)->update([ 'invitation_link' => Str::uuid()->toString(), ]); Mail::to($employee->email) ->queue(new InviteEmployeeToBecomeUserMail($employee->refresh())); } }
-
resources/views/emails/company/invitation.blade.php
Open in GitHub@component('mail::message') # You are invited to join {{ $employee->company->name }}. An employee of {{ $employee->company->name }} would like you to join them on OfficeLife, the software used to manage human resources. If you do already have an account on OfficeLife, you will be able to use your existing account. @component('mail::button', ['url' => $employee->getPathInvitationLink()]) Join {{ $employee->company->name }} on OfficeLife @endcomponent Thanks,<br> {{ config('app.name') }} @endcomponent