coolify/app/Models/Project.php

60 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
class Project extends BaseModel
{
2023-08-22 17:44:49 +02:00
protected $guarded = [];
static public function ownedByCurrentTeam()
{
2023-08-22 17:44:49 +02:00
return Project::whereTeamId(currentTeam()->id)->orderBy('name');
}
protected static function booted()
{
static::created(function ($project) {
ProjectSetting::create([
'project_id' => $project->id,
]);
2023-04-25 14:43:35 +02:00
Environment::create([
'name' => 'production',
2023-04-25 14:43:35 +02:00
'project_id' => $project->id,
]);
});
2023-10-05 08:46:26 +02:00
static::deleting(function ($project) {
$project->environments()->delete();
$project->settings()->delete();
});
}
2023-04-25 14:43:35 +02:00
public function environments()
{
return $this->hasMany(Environment::class);
}
2023-04-25 14:43:35 +02:00
public function settings()
{
return $this->hasOne(ProjectSetting::class);
}
public function team()
{
return $this->belongsTo(Team::class);
}
2023-04-25 14:43:35 +02:00
public function applications()
{
2023-03-30 19:50:27 +02:00
return $this->hasManyThrough(Application::class, Environment::class);
}
2023-08-07 18:46:40 +02:00
public function postgresqls()
{
2023-08-07 22:14:21 +02:00
return $this->hasManyThrough(StandalonePostgresql::class, Environment::class);
2023-08-07 18:46:40 +02:00
}
2023-10-12 17:18:33 +02:00
public function redis()
{
return $this->hasManyThrough(StandaloneRedis::class, Environment::class);
}
2023-08-07 22:14:21 +02:00
}