use App\Jobs\DeploySite;
use Illuminate\Database\Eloquent\Model;
class Site extends Model
{
// ...
public function deploy(array $environmentVariables = [], User $user = null): Deployment
{
if ($this->fresh()->latestDeployment?->status === DeploymentStatus::Pending) {
throw new PendingDeploymentException($this);
}
/** @var Deployment */
$deployment = $this->deployments()->create([
'status' => DeploymentStatus::Pending,
'user_id' => $user?->exists ? $user->id : null,
]);
$this->server->team->activityLogs()->create([
'subject_id' => $this->getKey(),
'subject_type' => $this->getMorphClass(),
'description' => __(__("Deployed site ':address' on server ':server'", ['address' => $this->address, 'server' => $this->server->name])),
'user_id' => $user?->exists ? $user->id : null,
]);
dispatch(new DeploySite($deployment, $environmentVariables));
return $deployment;
}
// ...
}