An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Add projects, environments, applications, databases
Andras Bacsai1c87146a50fd
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.phpnew file mode 100644index 0000000000..f3e9876820--- /dev/null+++ b/app/Http/Controllers/HomeController.php@@ -0,0 +1,12 @@+<?php++namespace App\Http\Controllers;++class HomeController extends Controller+{+ public function show()+ {+ $projects = session('currentTeam')->projects;+ return view('home', ['projects' => $projects]);+ }+}diff --git a/app/Models/Application.php b/app/Models/Application.phpnew file mode 100644index 0000000000..0ac9475b8a--- /dev/null+++ b/app/Models/Application.php@@ -0,0 +1,11 @@+<?php++namespace App\Models;++class Application extends BaseModel+{+ public function environments()+ {+ return $this->morphToMany(Environment::class, 'environmentable');+ }+}diff --git a/app/Models/Database.php b/app/Models/Database.phpnew file mode 100644index 0000000000..5aa1f27471--- /dev/null+++ b/app/Models/Database.php@@ -0,0 +1,11 @@+<?php++namespace App\Models;++class Database extends BaseModel+{+ public function environments()+ {+ return $this->morphToMany(Environment::class, 'environmentable');+ }+}diff --git a/app/Models/Environment.php b/app/Models/Environment.phpnew file mode 100644index 0000000000..a8a98cca6e--- /dev/null+++ b/app/Models/Environment.php@@ -0,0 +1,20 @@+<?php++namespace App\Models;++class Environment extends BaseModel+{+ public function environmentables()+ {+ return $this->hasMany(EnvironmentAble::class);+ }+ public function applications()+ {+ return $this->morphedByMany(Application::class, 'environmentable');+ }+ public function databases()+ {+ return $this->morphedByMany(Database::class, 'environmentable');+ }+}+diff --git a/app/Models/Project.php b/app/Models/Project.phpnew file mode 100644index 0000000000..1efe885480--- /dev/null+++ b/app/Models/Project.php@@ -0,0 +1,13 @@+<?php++namespace App\Models;++class Project extends BaseModel+{+ public function environments() {+ return $this->hasMany(Environment::class);+ }+ public function settings() {+ return $this->hasOne(ProjectSetting::class);+ }+}diff --git a/app/Models/ProjectSetting.php b/app/Models/ProjectSetting.phpnew file mode 100644index 0000000000..78dcb32ba9--- /dev/null+++ b/app/Models/ProjectSetting.php@@ -0,0 +1,7 @@+<?php++namespace App\Models;++class ProjectSetting extends BaseModel+{+}diff --git a/app/Models/Team.php b/app/Models/Team.phpindex 90d4d73d93..e4118d860d 100644--- a/app/Models/Team.php+++ b/app/Models/Team.php@@ -10,4 +10,7 @@ class Team extends BaseModelprotected $fillable = ['name',];+ public function projects() {+ return $this->hasMany(Project::class);+ }}diff --git a/database/migrations/2023_03_27_075351_create_projects_table.php b/database/migrations/2023_03_27_075351_create_projects_table.phpnew file mode 100644index 0000000000..432496268e--- /dev/null+++ b/database/migrations/2023_03_27_075351_create_projects_table.php@@ -0,0 +1,33 @@+<?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('projects', function (Blueprint $table) {+ $table->id();+ $table->string('uuid')->unique();+ $table->string('name');+ $table->string('description')->nullable();++ $table->foreignId('team_id');++ $table->timestamps();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::dropIfExists('projects');+ }+};diff --git a/database/migrations/2023_03_27_075443_create_project_settings_table.php b/database/migrations/2023_03_27_075443_create_project_settings_table.phpnew file mode 100644index 0000000000..40e8bed1fa--- /dev/null+++ b/database/migrations/2023_03_27_075443_create_project_settings_table.php@@ -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('project_settings', function (Blueprint $table) {+ $table->id();+ $table->string('uuid')->unique();+ $table->string('wildcard_domain')->nullable();++ $table->foreignId('project_id');++ $table->timestamps();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::dropIfExists('project_settings');+ }+};diff --git a/database/migrations/2023_03_27_075444_create_environments_table.php b/database/migrations/2023_03_27_075444_create_environments_table.phpnew file mode 100644index 0000000000..efb1bfcb4f--- /dev/null+++ b/database/migrations/2023_03_27_075444_create_environments_table.php@@ -0,0 +1,33 @@+<?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('environments', function (Blueprint $table) {+ $table->id();+ $table->string('uuid')->unique();+ $table->string('name')->unique();++ $table->nullableMorphs('environments_morph');++ $table->foreignId('project_id');+ $table->timestamps();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::dropIfExists('environments');+ }+};diff --git a/database/migrations/2023_03_27_075445_create_environmentsables_table.php b/database/migrations/2023_03_27_075445_create_environmentsables_table.phpnew file mode 100644index 0000000000..36dd52ed1c--- /dev/null+++ b/database/migrations/2023_03_27_075445_create_environmentsables_table.php@@ -0,0 +1,30 @@+<?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('environmentables', function (Blueprint $table) {+ $table->id();+ $table->unsignedBigInteger('environment_id');+ $table->unsignedBigInteger('environmentable_id');+ $table->string('environmentable_type');+ $table->timestamps();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::dropIfExists('environmentables');+ }+};diff --git a/database/migrations/2023_03_27_081716_create_applications_table.php b/database/migrations/2023_03_27_081716_create_applications_table.phpnew file mode 100644index 0000000000..bdfb38fefb--- /dev/null+++ b/database/migrations/2023_03_27_081716_create_applications_table.php@@ -0,0 +1,29 @@+<?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('applications', function (Blueprint $table) {+ $table->id();+ $table->string('uuid')->unique();+ $table->string('name');+ $table->timestamps();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::dropIfExists('applications');+ }+};diff --git a/database/migrations/2023_03_27_083620_create_databases_table.php b/database/migrations/2023_03_27_083620_create_databases_table.phpnew file mode 100644index 0000000000..cf81de07f5--- /dev/null+++ b/database/migrations/2023_03_27_083620_create_databases_table.php@@ -0,0 +1,29 @@+<?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('databases', function (Blueprint $table) {+ $table->id();+ $table->string('uuid')->unique();+ $table->string('name');+ $table->timestamps();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::dropIfExists('databases');+ }+};diff --git a/database/seeders/ApplicationSeeder.php b/database/seeders/ApplicationSeeder.phpnew file mode 100644index 0000000000..f75b017b73--- /dev/null+++ b/database/seeders/ApplicationSeeder.php@@ -0,0 +1,25 @@+<?php++namespace Database\Seeders;++use App\Models\Application;+use App\Models\Environment;+use App\Models\Project;+use Illuminate\Database\Console\Seeds\WithoutModelEvents;+use Illuminate\Database\Seeder;++class ApplicationSeeder extends Seeder+{+ /**+ * Run the database seeds.+ */+ public function run(): void+ {+ $environment_1 = Environment::find(1);+ $application_1 = Application::create([+ 'id' => 1,+ 'name' => 'My first application',+ ]);+ $environment_1->applications()->attach($application_1);+ }+}diff --git a/database/seeders/DBSeeder.php b/database/seeders/DBSeeder.phpnew file mode 100644index 0000000000..adf09e0489--- /dev/null+++ b/database/seeders/DBSeeder.php@@ -0,0 +1,21 @@+<?php++namespace Database\Seeders;++use App\Models\Database;+use App\Models\Environment;+use Illuminate\Database\Seeder;++class DBSeeder extends Seeder+{+ public function run(): void+ {+ $environment_1 = Environment::find(1);+ $database_1 = Database::create([+ 'id' => 1,+ 'name'=> "My first database"+ ]);++ $environment_1->databases()->attach($database_1);+ }+}diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.phpindex 19606f85a7..8f9ad67c7a 100644--- a/database/seeders/DatabaseSeeder.php+++ b/database/seeders/DatabaseSeeder.php@@ -14,6 +14,11 @@ class DatabaseSeeder extends SeederTeamSeeder::class,ServerSeeder::class,PrivateKeySeeder::class,+ ProjectSeeder::class,+ ProjectSettingSeeder::class,+ EnvironmentSeeder::class,+ ApplicationSeeder::class,+ DBSeeder::class,]);}}diff --git a/database/seeders/EnvironmentSeeder.php b/database/seeders/EnvironmentSeeder.phpnew file mode 100644index 0000000000..b06a70c5fe--- /dev/null+++ b/database/seeders/EnvironmentSeeder.php@@ -0,0 +1,24 @@+<?php++namespace Database\Seeders;++use App\Models\Environment;+use App\Models\Project;+use Illuminate\Database\Console\Seeds\WithoutModelEvents;+use Illuminate\Database\Seeder;++class EnvironmentSeeder extends Seeder+{+ /**+ * Run the database seeds.+ */+ public function run(): void+ {+ $project_1 = Project::find(1);+ Environment::create([+ 'id' => 1,+ 'name' => 'production',+ 'project_id' => $project_1->id,+ ]);+ }+}diff --git a/database/seeders/ProjectSeeder.php b/database/seeders/ProjectSeeder.phpnew file mode 100644index 0000000000..c43a69e5c3--- /dev/null+++ b/database/seeders/ProjectSeeder.php@@ -0,0 +1,21 @@+<?php++namespace Database\Seeders;++use App\Models\Project;+use App\Models\Team;+use Illuminate\Database\Seeder;++class ProjectSeeder extends Seeder+{+ public function run(): void+ {+ $root_team = Team::find(1);+ Project::create([+ 'id' => 1,+ 'name' => "My first project",+ 'description' => "This is a test project in development",+ 'team_id' => $root_team->id,+ ]);+ }+}diff --git a/database/seeders/ProjectSettingSeeder.php b/database/seeders/ProjectSettingSeeder.phpnew file mode 100644index 0000000000..050982beee--- /dev/null+++ b/database/seeders/ProjectSettingSeeder.php@@ -0,0 +1,20 @@+<?php++namespace Database\Seeders;++use App\Models\Project;+use App\Models\ProjectSetting;+use Illuminate\Database\Seeder;++class ProjectSettingSeeder extends Seeder+{+ public function run(): void+ {+ $first_project = Project::find(1);+ ProjectSetting::create([+ 'id' => 1,+ 'wildcard_domain' => 'testing-host.localhost',+ 'project_id' => $first_project->id,+ ]);+ }+}diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.phpindex 008e4a57b9..14507b8a62 100644--- a/resources/views/components/navbar.blade.php+++ b/resources/views/components/navbar.blade.php@@ -1,10 +1,10 @@<nav>- <a href="/">Home</a>@guest<a href="/login">Login</a><a href="/register">Register</a>@endguest@auth+ <a href="/">Home</a><a href="/demo">Demo</a><a href="/profile">Profile</a><form action="/logout" method="POST">diff --git a/resources/views/home.blade.php b/resources/views/home.blade.phpindex 0e3e3b0cce..13d214e82a 100644--- a/resources/views/home.blade.php+++ b/resources/views/home.blade.php@@ -2,9 +2,23 @@<h1>Coolify v4 🎉</h1>- @guest- <p>- To see the demo, please <a href='/login'>login<a> or <a href='/register'>register<a>.- </p>- @endguest+ <h2>Projects</h2>+ <ul>+ @forelse ($projects as $project)+ <li>+ <p>Project Name: {{ $project->name }}</p>+ <p>Project Settings:{{ $project->settings }}</p>+ <h2>Environments</h2>+ @forelse ($project->environments as $environment)+ <p>Environment Name: {{ $environment->name }}</p>+ <p>Applications: {{ $environment->applications }}</p>+ <p>Databases: {{ $environment->databases }}</p>+ @empty+ <p>No environments found</p>+ @endforelse+ </li>+ @empty+ <li>No projects found</li>+ @endforelse+ </ul></x-layout>diff --git a/routes/web.php b/routes/web.phpindex ff3fd599ea..18cde30a78 100644--- a/routes/web.php+++ b/routes/web.php@@ -1,5 +1,6 @@<?php+use App\Http\Controllers\HomeController;use Illuminate\Support\Facades\Route;/*@@ -13,11 +14,10 @@ use Illuminate\Support\Facades\Route;|*/-Route::get('/', function () {- return view('home');-});+Route::middleware(['auth'])->group(function () {+ Route::get('/', [HomeController::class, 'show']);Route::get('/profile', function () {return view('profile');});