auditionadmin/app/Actions/Schools/AddSchoolEmailDomain.php

36 lines
818 B
PHP

<?php
namespace App\Actions\Schools;
use App\Exceptions\AuditionAdminException;
use App\Models\School;
use App\Models\SchoolEmailDomain;
class AddSchoolEmailDomain
{
public function __construct()
{
}
public function __invoke(School $school, string $domain): void
{
$this->addDomain($school, $domain);
}
public function addDomain(School $school, string $domain): void
{
if (! School::where('id', $school->id)->exists()) {
throw new AuditionAdminException('School does not exist');
}
if (SchoolEmailDomain::where('domain', $domain)->where('school_id', $school->id)->exists()) {
return;
}
SchoolEmailDomain::create([
'domain' => $domain,
'school_id' => $school->id,
]);
}
}