2023-03-27 08:44:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
class Project extends BaseModel
|
|
|
|
{
|
2023-08-22 15:44:49 +00:00
|
|
|
protected $guarded = [];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
static public function ownedByCurrentTeam()
|
|
|
|
{
|
2023-08-22 15:44:49 +00:00
|
|
|
return Project::whereTeamId(currentTeam()->id)->orderBy('name');
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 09:09:39 +00:00
|
|
|
protected static function booted()
|
|
|
|
{
|
|
|
|
static::created(function ($project) {
|
|
|
|
ProjectSetting::create([
|
|
|
|
'project_id' => $project->id,
|
|
|
|
]);
|
2023-04-25 12:43:35 +00:00
|
|
|
Environment::create([
|
2023-10-24 08:11:21 +00:00
|
|
|
'name' => 'production',
|
2023-04-25 12:43:35 +00:00
|
|
|
'project_id' => $project->id,
|
|
|
|
]);
|
2023-03-30 09:09:39 +00:00
|
|
|
});
|
2023-10-05 06:46:26 +00:00
|
|
|
static::deleting(function ($project) {
|
2023-07-26 11:23:47 +00:00
|
|
|
$project->environments()->delete();
|
|
|
|
$project->settings()->delete();
|
|
|
|
});
|
2023-03-30 09:09:39 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-04-25 12:43:35 +00:00
|
|
|
public function environments()
|
|
|
|
{
|
2023-03-27 08:44:31 +00:00
|
|
|
return $this->hasMany(Environment::class);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-04-25 12:43:35 +00:00
|
|
|
public function settings()
|
|
|
|
{
|
2023-03-27 08:44:31 +00:00
|
|
|
return $this->hasOne(ProjectSetting::class);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function team()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Team::class);
|
|
|
|
}
|
|
|
|
|
2023-04-25 12:43:35 +00:00
|
|
|
public function applications()
|
|
|
|
{
|
2023-03-30 17:50:27 +00:00
|
|
|
return $this->hasManyThrough(Application::class, Environment::class);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-08-07 16:46:40 +00:00
|
|
|
public function postgresqls()
|
|
|
|
{
|
2023-08-07 20:14:21 +00:00
|
|
|
return $this->hasManyThrough(StandalonePostgresql::class, Environment::class);
|
2023-08-07 16:46:40 +00:00
|
|
|
}
|
2023-10-12 15:18:33 +00:00
|
|
|
public function redis()
|
|
|
|
{
|
|
|
|
return $this->hasManyThrough(StandaloneRedis::class, Environment::class);
|
|
|
|
}
|
2023-10-24 12:31:28 +00:00
|
|
|
public function mongodbs()
|
|
|
|
{
|
|
|
|
return $this->hasManyThrough(StandaloneMongodb::class, Environment::class);
|
|
|
|
}
|
|
|
|
public function mysqls()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StandaloneMysql::class, Environment::class);
|
|
|
|
}
|
|
|
|
public function mariadbs()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StandaloneMariadb::class, Environment::class);
|
|
|
|
}
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|