Add Service
This commit is contained in:
		
							parent
							
								
									f7dd65d1e1
								
							
						
					
					
						commit
						f4daffaa89
					
				| @ -12,5 +12,9 @@ class Environment extends BaseModel | ||||
|     { | ||||
|         return $this->hasMany(Database::class); | ||||
|     } | ||||
|     public function services() | ||||
|     { | ||||
|         return $this->hasMany(Service::class); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										16
									
								
								app/Models/Service.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								app/Models/Service.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace App\Models; | ||||
| 
 | ||||
| 
 | ||||
| class Service extends BaseModel | ||||
| { | ||||
|     public function environment() | ||||
|     { | ||||
|         return $this->belongsTo(Environment::class); | ||||
|     } | ||||
|     public function destination() | ||||
|     { | ||||
|         return $this->morphTo(); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,32 @@ | ||||
| <?php | ||||
| 
 | ||||
| use Illuminate\Database\Migrations\Migration; | ||||
| use Illuminate\Database\Schema\Blueprint; | ||||
| use Illuminate\Support\Facades\Schema; | ||||
| 
 | ||||
| return new class extends Migration | ||||
| { | ||||
|     /** | ||||
|      * Run the migrations. | ||||
|      */ | ||||
|     public function up(): void | ||||
|     { | ||||
|         Schema::create('services', function (Blueprint $table) { | ||||
|             $table->id(); | ||||
|             $table->string('uuid')->unique(); | ||||
|             $table->string('name'); | ||||
| 
 | ||||
|             $table->morphs('destination'); | ||||
|             $table->foreignId('environment_id'); | ||||
|             $table->timestamps(); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Reverse the migrations. | ||||
|      */ | ||||
|     public function down(): void | ||||
|     { | ||||
|         Schema::dropIfExists('services'); | ||||
|     } | ||||
| }; | ||||
| @ -28,7 +28,7 @@ class ApplicationSeeder extends Seeder | ||||
|         ]); | ||||
|         Application::create([ | ||||
|             'id' => 2, | ||||
|             'name' => 'My Second application', | ||||
|             'name' => 'My second application (Swarm)', | ||||
|             'environment_id' => $environment_1->id, | ||||
|             'destination_id' => $swarm_docker_1->id, | ||||
|             'destination_type' => SwarmDocker::class, | ||||
|  | ||||
| @ -20,7 +20,5 @@ class DBSeeder extends Seeder | ||||
|             'destination_id' => $standalone_docker_1->id, | ||||
|             'destination_type' => StandaloneDocker::class, | ||||
|         ]); | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -23,6 +23,7 @@ class DatabaseSeeder extends Seeder | ||||
|                 KubernetesSeeder::class, | ||||
|                 ApplicationSeeder::class, | ||||
|                 DBSeeder::class, | ||||
|                 ServiceSeeder::class, | ||||
|             ]); | ||||
|         } | ||||
|     } | ||||
|  | ||||
							
								
								
									
										27
									
								
								database/seeders/ServiceSeeder.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								database/seeders/ServiceSeeder.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Database\Seeders; | ||||
| 
 | ||||
| use App\Models\Environment; | ||||
| use App\Models\Service; | ||||
| use App\Models\StandaloneDocker; | ||||
| use Illuminate\Database\Seeder; | ||||
| 
 | ||||
| class ServiceSeeder extends Seeder | ||||
| { | ||||
|     /** | ||||
|      * Run the database seeds. | ||||
|      */ | ||||
|     public function run(): void | ||||
|     { | ||||
|         $environment_1 = Environment::find(1); | ||||
|         $standalone_docker_1 = StandaloneDocker::find(1); | ||||
|         Service::create([ | ||||
|             'id' => 1, | ||||
|             'name'=> "My first database", | ||||
|             'environment_id' => $environment_1->id, | ||||
|             'destination_id' => $standalone_docker_1->id, | ||||
|             'destination_type' => StandaloneDocker::class, | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @ -5,31 +5,40 @@ | ||||
|     <h1>Projects</h1> | ||||
|     <ul> | ||||
|         @forelse ($projects as $project) | ||||
|                 <h2>{{ $project->name }}</h2> | ||||
|                 <p>Project Settings:{{ $project->settings }}</p> | ||||
|                 <h2>Environments</h2> | ||||
|                 @forelse ($project->environments as $environment) | ||||
|                     <p>Environment Name: {{ $environment->name }}</p> | ||||
|                     <h2>Applications</h2> | ||||
|                     @forelse ($environment->applications as $application) | ||||
|                         <h3>{{ $application->name }}</h3> | ||||
|                         <p>Application: {{ $application }}</p> | ||||
|                         <p>Destination Class: {{ $application->destination->getMorphClass() }}</p> | ||||
|                     @empty | ||||
|             <li>No application found</li> | ||||
|         @endforelse | ||||
|         <h2>Databases</h2> | ||||
|         @forelse ($environment->databases as $database) | ||||
|             <h3>{{ $database->name }}</h3> | ||||
|             <p>Database: {{ $database }}</p> | ||||
|             <h2>{{ $project->name }}</h2> | ||||
|             <p>Project Settings:{{ $project->settings }}</p> | ||||
|             <h2>Environments</h2> | ||||
|             @forelse ($project->environments as $environment) | ||||
|                 <h1>Environment: {{ $environment->name }}</h1> | ||||
|                 <h2>Applications</h2> | ||||
|                 @forelse ($environment->applications as $application) | ||||
|                     <h3>{{ $application->name }}</h3> | ||||
|                     <p>Application: {{ $application }}</p> | ||||
|                     <p>Destination Class: {{ $application->destination->getMorphClass() }}</p> | ||||
|                 @empty | ||||
|                     <li>No application found</li> | ||||
|                 @endforelse | ||||
|                 <h2>Databases</h2> | ||||
|                 @forelse ($environment->databases as $database) | ||||
|                     <h3>{{ $database->name }}</h3> | ||||
|                     <p>Database: {{ $database }}</p> | ||||
|                     <p>Destination Class: {{ $database->destination->getMorphClass() }}</p> | ||||
|                 @empty | ||||
|                     <li>No database found</li> | ||||
|                 @endforelse | ||||
|                 <h2>Services</h2> | ||||
|                 @forelse ($environment->services as $service) | ||||
|                     <h3>{{ $service->name }}</h3> | ||||
|                     <p>Service: {{ $service }}</p> | ||||
|                     <p>Destination Class: {{ $service->destination->getMorphClass() }}</p> | ||||
|                 @empty | ||||
|                     <li>No service found</li> | ||||
|                 @endforelse | ||||
|             @empty | ||||
|                 <p>No environments found</p> | ||||
|             @endforelse | ||||
|         @empty | ||||
|             <li>No database found</li> | ||||
|         @endforelse | ||||
|     @empty | ||||
|         <p>No environments found</p> | ||||
|         @endforelse | ||||
|     @empty | ||||
|         <li>No projects found</li> | ||||
|             <li>No projects found</li> | ||||
|         @endforelse | ||||
|     </ul> | ||||
| </x-layout> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user