lasthourcloud/app/Models/Project.php

61 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
class Project extends BaseModel
{
protected $fillable = [
'name',
'description',
'team_id',
'project_id'
];
static public function ownedByCurrentTeam()
{
2023-08-11 15:31:53 +00:00
return Project::whereTeamId(auth()->user()->currentTeam()->id)->orderBy('name');
}
protected static function booted()
{
static::created(function ($project) {
ProjectSetting::create([
'project_id' => $project->id,
]);
2023-04-25 12:43:35 +00:00
Environment::create([
'name' => 'Production',
'project_id' => $project->id,
]);
});
static::deleted(function ($project) {
$project->environments()->delete();
$project->settings()->delete();
});
}
2023-04-25 12:43:35 +00:00
public function environments()
{
return $this->hasMany(Environment::class);
}
2023-04-25 12:43:35 +00:00
public function settings()
{
return $this->hasOne(ProjectSetting::class);
}
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-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-08-07 20:14:21 +00:00
}