diff --git a/app/Http/Controllers/admin/package/Datastore.php b/app/Http/Controllers/admin/package/Datastore.php index c89aef6..8a8dc5e 100644 --- a/app/Http/Controllers/admin/package/Datastore.php +++ b/app/Http/Controllers/admin/package/Datastore.php @@ -71,7 +71,7 @@ class Datastore extends Controller public function edit(int $id = 0) { $datastore = $this->datastoreRepository->findWithRelationships($id, ['host.datacenter']); - + if (!$datastore) { return back()->withErrors('Invalid Request'); } diff --git a/app/Repositories/Module/Datastore/DatastoreRepository.php b/app/Repositories/Module/Datastore/DatastoreRepository.php index a4f1e82..cb32501 100644 --- a/app/Repositories/Module/Datastore/DatastoreRepository.php +++ b/app/Repositories/Module/Datastore/DatastoreRepository.php @@ -40,11 +40,16 @@ class DatastoreRepository extends BaseRepository implements DatastoreRepositoryI { $model = $this->model; if (count($relationships) > 0) { + $validRelationships = []; foreach ($relationships as $relationship) { - if (method_exists($model, $relationship)) { - $model = $model->with($relationship); + $firstRelation = explode('.', $relationship)[0]; + if (method_exists($model, $firstRelation)) { + $validRelationships[] = $relationship; } } + if (count($validRelationships) > 0) { + $model = $model->with($validRelationships); + } } // Xử lý withCount diff --git a/database/migrations/2024_02_01_091707_module_datastore.php b/database/migrations/2024_02_01_091707_module_datastore.php index 56129bc..3b72ffa 100644 --- a/database/migrations/2024_02_01_091707_module_datastore.php +++ b/database/migrations/2024_02_01_091707_module_datastore.php @@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * @@ -13,13 +12,13 @@ return new class extends Migration */ public function up() { - Schema::create('module_datastore',function (Blueprint $table) { + Schema::create('module_datastore', function (Blueprint $table) { $table->id()->autoIncrement(); - $table->string('name',255)->nullable(); - $table->string('datastore',255)->nullable(); - $table->string('type',100)->nullable(); + $table->string('name', 255)->nullable(); + $table->string('datastore', 255)->nullable(); + $table->string('type', 100)->nullable(); $table->integer('space')->nullable(); - $table->bigInteger('module_host_id')->default(0)->index(); + $table->foreignId('module_host_id')->index()->constrained('module_hosts')->cascadeOnDelete(); $table->tinyInteger('status')->default(1); $table->timestamps(); }); @@ -32,6 +31,6 @@ return new class extends Migration */ public function down() { - Schema::dropIfExists('module_datastores'); + Schema::dropIfExists('module_datastore'); } }; diff --git a/database/migrations/2026_01_31_111040_update_table_module_datastore_table.php b/database/migrations/2026_01_31_111040_update_table_module_datastore_table.php new file mode 100644 index 0000000..c4d9120 --- /dev/null +++ b/database/migrations/2026_01_31_111040_update_table_module_datastore_table.php @@ -0,0 +1,32 @@ +unsignedBigInteger('module_host_id')->default(0)->change(); + }); + + Schema::table('module_datastore', function (Blueprint $table) { + $table->foreign('module_host_id') + ->references('id') + ->on('module_host') + ->cascadeOnDelete(); + }); + } + + public function down(): void + { + Schema::table('module_datastore', function (Blueprint $table) { + $table->dropForeign(['module_host_id']); + }); + + Schema::table('module_datastore', function (Blueprint $table) { + $table->bigInteger('module_host_id')->default(0)->change(); + }); + } +}; diff --git a/resources/views/administrator/pages/package/datastore/add.blade.php b/resources/views/administrator/pages/package/datastore/add.blade.php index 90b6560..dded2fc 100644 --- a/resources/views/administrator/pages/package/datastore/add.blade.php +++ b/resources/views/administrator/pages/package/datastore/add.blade.php @@ -52,11 +52,11 @@
- +
- + +
diff --git a/resources/views/administrator/pages/package/datastore/edit.blade.php b/resources/views/administrator/pages/package/datastore/edit.blade.php index 8efc25a..efc7349 100644 --- a/resources/views/administrator/pages/package/datastore/edit.blade.php +++ b/resources/views/administrator/pages/package/datastore/edit.blade.php @@ -56,11 +56,11 @@
- +
- + +