Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

officelifehq/officelife

942 stars
3 code files
View officelifehq/officelife on GitHub

app/Mail/Company/InviteEmployeeToBecomeUserMail.php

Open in GitHub
use 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 GitHub
use 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

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.