diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index 65341a7..3089066 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -97,14 +97,24 @@ public function subClassification(Request $request){ if ($request->ajax()) { $classificationParam = $request->input('classification', null); + if ($classificationParam) { + $classification = Classification::where('id', '=', decrypt_id($classificationParam))->first(); - if($classificationParam){ - $classification = Classification::where('slug', '=', $classificationParam)->first(); - $data = SubClassification::with(['classification'])->where('classification_id', '=', $classification->id)->get(); - }else{ - $data = SubClassification::with(['classification'])->get(); + // Tambahkan pengecekan apakah classification ditemukan + if ($classification) { + $data = SubClassification::with(['classification' => function($query) { + $query->withTrashed(); + }])->where('classification_id', '=', $classification->id)->get(); + } else { + return response()->json(['error' => 'Classification not found'], 404); + } + } else { + $data = SubClassification::with(['classification' => function($query) { + $query->withTrashed(); + }])->get(); } + return DataTables::of($data) ->addIndexColumn() ->addColumn('classification', function ($data) { diff --git a/app/Models/Legacy/OldSubClassification.php b/app/Models/Legacy/OldSubClassification.php new file mode 100644 index 0000000..ce1e4a2 --- /dev/null +++ b/app/Models/Legacy/OldSubClassification.php @@ -0,0 +1,15 @@ +id(); $table->string('name'); - $table->string('slug')->unique();; $table->text('description')->nullable(); $table->enum('status', ['0', '1'])->default('0'); $table->unsignedBigInteger('classification_id'); @@ -22,6 +21,7 @@ public function up(): void $table->unsignedBigInteger('enhancer_id'); $table->foreign('enhancer_id')->references('id')->on('users'); $table->timestamps(); + $table->softDeletes(); }); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 1528dd6..bb0c58a 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -16,10 +16,10 @@ public function run(): void $this->call(RoleSeeder::class); $this->call(UserSeeder::class); $this->call(ClassificationSeeder::class); + $this->call(SubClassificationSeeder::class); $this->call(CompanySeeder::class); $this->call(MediaSeeder::class); $this->call(JournalistSeeder::class); - $this->call(SubClassificationSeeder::class); $this->call(GovernmentAgencySeeder::class); } } diff --git a/database/seeders/SubClassificationSeeder.php b/database/seeders/SubClassificationSeeder.php index 5d500a6..467fb2a 100644 --- a/database/seeders/SubClassificationSeeder.php +++ b/database/seeders/SubClassificationSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Models\Legacy\OldSubClassification; use App\Models\SubClassification; use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; @@ -13,6 +14,20 @@ class SubClassificationSeeder extends Seeder */ public function run(): void { - // + $legacySubClassifications = OldSubClassification::withTrashed()->get(); + + foreach($legacySubClassifications as $legacySubClassification){ + SubClassification::create([ + 'id' => $legacySubClassification->id, + 'name' => $legacySubClassification->name, + 'status' => $legacySubClassification->status, + 'description' => null, + 'created_at' => $legacySubClassification->created_at, + 'updated_at' => $legacySubClassification->updated_at, + 'deleted_at' => $legacySubClassification->deleted_at, + 'classification_id' => $legacySubClassification->classification, + 'enhancer_id' => $legacySubClassification->enhancer, + ]); + } } } diff --git a/resources/views/dashboard/sub-classifications/show.blade.php b/resources/views/dashboard/sub-classifications/show.blade.php index 9bf59c8..c35ba91 100644 --- a/resources/views/dashboard/sub-classifications/show.blade.php +++ b/resources/views/dashboard/sub-classifications/show.blade.php @@ -1,5 +1,5 @@ @include('partials.dashboard.head') -@include('partials.dashboard.sidebar', ['page' => 'sub_classifications']) +@include('partials.dashboard.sidebar', ['page' => 'journalists']) @include('partials.dashboard.header')