2023-03-27 10:44:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
class Project extends BaseModel
|
|
|
|
{
|
2023-08-22 17:44:49 +02:00
|
|
|
protected $guarded = [];
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
static public function ownedByCurrentTeam()
|
|
|
|
{
|
2023-08-22 17:44:49 +02:00
|
|
|
return Project::whereTeamId(currentTeam()->id)->orderBy('name');
|
2023-08-08 11:51:36 +02:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:09:39 +02:00
|
|
|
protected static function booted()
|
|
|
|
{
|
|
|
|
static::created(function ($project) {
|
|
|
|
ProjectSetting::create([
|
|
|
|
'project_id' => $project->id,
|
|
|
|
]);
|
2023-04-25 14:43:35 +02:00
|
|
|
Environment::create([
|
2023-10-24 10:11:21 +02:00
|
|
|
'name' => 'production',
|
2023-04-25 14:43:35 +02:00
|
|
|
'project_id' => $project->id,
|
|
|
|
]);
|
2023-03-30 11:09:39 +02:00
|
|
|
});
|
2023-10-05 08:46:26 +02:00
|
|
|
static::deleting(function ($project) {
|
2023-07-26 13:23:47 +02:00
|
|
|
$project->environments()->delete();
|
|
|
|
$project->settings()->delete();
|
|
|
|
});
|
2023-03-30 11:09:39 +02:00
|
|
|
}
|
2024-03-07 11:35:00 +01:00
|
|
|
public function environment_variables()
|
|
|
|
{
|
2024-01-23 17:13:23 +01:00
|
|
|
return $this->hasMany(SharedEnvironmentVariable::class);
|
|
|
|
}
|
2023-04-25 14:43:35 +02:00
|
|
|
public function environments()
|
|
|
|
{
|
2023-03-27 10:44:31 +02:00
|
|
|
return $this->hasMany(Environment::class);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-04-25 14:43:35 +02:00
|
|
|
public function settings()
|
|
|
|
{
|
2023-03-27 10:44:31 +02:00
|
|
|
return $this->hasOne(ProjectSetting::class);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
public function team()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Team::class);
|
|
|
|
}
|
|
|
|
|
2024-03-07 11:14:03 +01:00
|
|
|
public function services()
|
|
|
|
{
|
|
|
|
return $this->hasManyThrough(Service::class, Environment::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-08 11:51:36 +02:00
|
|
|
|
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-10-24 14:31:28 +02:00
|
|
|
public function mongodbs()
|
|
|
|
{
|
|
|
|
return $this->hasManyThrough(StandaloneMongodb::class, Environment::class);
|
|
|
|
}
|
|
|
|
public function mysqls()
|
|
|
|
{
|
2024-01-31 14:18:59 +01:00
|
|
|
return $this->hasManyThrough(StandaloneMysql::class, Environment::class);
|
2023-10-24 14:31:28 +02:00
|
|
|
}
|
|
|
|
public function mariadbs()
|
|
|
|
{
|
2024-01-31 14:18:59 +01:00
|
|
|
return $this->hasManyThrough(StandaloneMariadb::class, Environment::class);
|
|
|
|
}
|
2024-03-07 11:35:00 +01:00
|
|
|
public function resource_count()
|
|
|
|
{
|
2024-01-31 14:18:59 +01:00
|
|
|
return $this->applications()->count() + $this->postgresqls()->count() + $this->redis()->count() + $this->mongodbs()->count() + $this->mysqls()->count() + $this->mariadbs()->count();
|
2023-10-24 14:31:28 +02:00
|
|
|
}
|
2023-08-07 22:14:21 +02:00
|
|
|
}
|