diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index f3e987682..7e96700a0 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -6,7 +6,7 @@ class HomeController extends Controller { public function show() { - $projects = session('currentTeam')->projects; + $projects = session('currentTeam')->load(['projects'])->projects; return view('home', ['projects' => $projects]); } } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 3641d3200..dbca37172 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -11,7 +11,7 @@ class ProjectController extends Controller { public function environments() { - $project = session('currentTeam')->projects->where('uuid', request()->route('project_uuid'))->first(); + $project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first()->load(['environments']); if (!$project) { return redirect()->route('home'); } @@ -19,17 +19,27 @@ public function environments() } public function resources() { - $project = session('currentTeam')->projects->where('uuid', request()->route('project_uuid'))->first(); + $project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first(); if (!$project) { return redirect()->route('home'); } - $environment = Environment::where('name', request()->route('environment_name'))->where('project_id', $project->id)->first(); - // $environment = $project->environments->where('name', request()->route('environment_name'))->first(); + $environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first(); + if (!$environment) { + return redirect()->route('home'); + } return view('project.resources', ['project' => $project, 'environment' => $environment]); } public function application() { - $application = Application::where('uuid', request()->route('application_uuid'))->first(); + $project = session('currentTeam')->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first(); + if (!$project) { + return redirect()->route('home'); + } + $environment = $project->load(['environments'])->environments->where('name', request()->route('environment_name'))->first()->load(['applications']); + if (!$environment) { + return redirect()->route('home'); + } + $application = $environment->applications->where('uuid', request()->route('application_uuid'))->first(); if (!$application) { return redirect()->route('home'); } @@ -38,7 +48,6 @@ public function application() public function deployment() { - $application_uuid = request()->route('application_uuid'); $deployment_uuid = request()->route('deployment_uuid'); $application = Application::where('uuid', request()->route('application_uuid'))->first(); diff --git a/app/Models/Project.php b/app/Models/Project.php index 0ebaf9d70..7dc0ef613 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -19,4 +19,7 @@ public function environments() { public function settings() { return $this->hasOne(ProjectSetting::class); } + public function applications() { + return $this->hasManyThrough(Application::class, Environment::class); + } } diff --git a/app/Models/Team.php b/app/Models/Team.php index 3b05aa1ee..55ffe6afb 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -16,4 +16,7 @@ public function projects() { public function servers() { return $this->hasMany(Server::class); } + public function applications() { + return $this->hasManyThrough(Application::class, Project::class); + } } diff --git a/resources/views/project/environments.blade.php b/resources/views/project/environments.blade.php index bf9efb655..ceb0a579c 100644 --- a/resources/views/project/environments.blade.php +++ b/resources/views/project/environments.blade.php @@ -1,6 +1,5 @@

Environments

- @foreach ($project->environments as $environment)
diff --git a/resources/views/project/resources.blade.php b/resources/views/project/resources.blade.php index 24f14d757..cf451b2c5 100644 --- a/resources/views/project/resources.blade.php +++ b/resources/views/project/resources.blade.php @@ -3,7 +3,7 @@
@foreach ($environment->applications as $application)

- + {{ $application->name }}

diff --git a/routes/web.php b/routes/web.php index f790904fa..17e02d287 100644 --- a/routes/web.php +++ b/routes/web.php @@ -23,8 +23,8 @@ Route::get('/project/{project_uuid}/{environment_name}', [ProjectController::class, 'resources'])->name('project.resources'); - Route::get('/application/{application_uuid}', [ProjectController::class, 'application'])->name('project.application'); - Route::get('/application/{application_uuid}/deployment/{deployment_uuid}', [ProjectController::class, 'deployment'])->name('project.deployment'); + Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}', [ProjectController::class, 'application'])->name('project.application'); + // Route::get('/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment/{deployment_uuid}', [ProjectController::class, 'deployment'])->name('project.deployment'); // Route::get('/database/{database_uuid}', [ProjectController::class, 'database'])->name('project.database'); // Route::get('//service/{service_uuid}', [ProjectController::class, 'service'])->name('project.service');