MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/snap.cafsinfotech.in/app/Services/InvitationService.php
<?php

namespace App\Services;

use App\Models\Invitation;
use Exception;
use Str;

class InvitationService
{
    /**
     * The invitation expires in one months.
     */
    protected const EXPIRATION_TIME_IN_DAYS = 30;

    /**
     * Create new invitation.
     *
     * @param array $user
     * @return Invitation|null
     * @throws Exception
     */
    public static function create(array $user): ?Invitation
    {
        return Invitation::create([
            'email' => $user['email'],
            'key' => Str::uuid(),
            'expires_at' => now()->addDays(self::EXPIRATION_TIME_IN_DAYS),
            'role_id' => $user['role_id']
        ]);
    }

    /**
     * Update invitation.
     *
     * @param int $id
     * @return Invitation|null
     * @throws Exception
     */
    public static function update(int $id): ?Invitation
    {
        return tap(Invitation::find($id))->update([
            'key' => Str::uuid(),
            'expires_at' => now()->addDays(self::EXPIRATION_TIME_IN_DAYS)
        ]);
    }
}