2023-03-27 08:44:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-04-25 12:43:35 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Environment extends Model
|
2023-03-27 08:44:31 +00:00
|
|
|
{
|
2023-04-25 12:43:35 +00:00
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'project_id',
|
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function can_delete_environment()
|
2023-04-25 12:43:35 +00:00
|
|
|
{
|
2023-08-07 16:46:40 +00:00
|
|
|
return $this->applications()->count() == 0 && $this->postgresqls()->count() == 0;
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-03-27 08:44:31 +00:00
|
|
|
public function applications()
|
|
|
|
{
|
2023-03-27 16:14:33 +00:00
|
|
|
return $this->hasMany(Application::class);
|
2023-03-27 08:44:31 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-08-07 16:46:40 +00:00
|
|
|
public function postgresqls()
|
2023-03-27 08:44:31 +00:00
|
|
|
{
|
2023-08-07 20:14:21 +00:00
|
|
|
return $this->hasMany(StandalonePostgresql::class);
|
2023-03-27 08:44:31 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function databases()
|
|
|
|
{
|
|
|
|
return $this->postgresqls();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function project()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Project::class);
|
|
|
|
}
|
|
|
|
|
2023-03-28 06:28:03 +00:00
|
|
|
public function services()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Service::class);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
protected function name(): Attribute
|
|
|
|
{
|
|
|
|
return Attribute::make(
|
2023-08-11 18:48:52 +00:00
|
|
|
set: fn (string $value) => strtolower($value),
|
2023-08-08 09:51:36 +00:00
|
|
|
);
|
|
|
|
}
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|