diff --git a/config/filament-sort-order.php b/config/filament-sort-order.php index 11552e3..5798b18 100644 --- a/config/filament-sort-order.php +++ b/config/filament-sort-order.php @@ -1,12 +1,16 @@ 'users', -// 'table2' =>'posts', -// 'table3' =>'products', -//And so on... return [ - 'table1' => 'users', + + /** Add the tables to be migrated */ + 'tables' => [ + 'users' + ], + + /* The column name to be used for sorting */ + 'sort_column_name' => 'sort_column', + + /* Sort Order asc or desc */ 'sort' => 'asc', ]; diff --git a/database/migrations/create_filament_sort_order_table.php.stub b/database/migrations/create_filament_sort_order_table.php.stub index facbe71..082e86a 100644 --- a/database/migrations/create_filament_sort_order_table.php.stub +++ b/database/migrations/create_filament_sort_order_table.php.stub @@ -8,21 +8,18 @@ return new class extends Migration { public function up() { - $sortOrder = 1; // Initial sort order value + + $sortColumn = config( 'filament-sort-order.sort_column_name', 'sort_order' ); - foreach (config('filament-sort-order') as $key => $table) { - if (strpos($key, 'table') === 0) { - Schema::table($table, function (Blueprint $table) { - $table->integer('sort_order')->unsigned()->default(0); - }); + foreach ( config( 'filament-sort-order.tables' ) as $key => $table ) { - $sortColumn = 'sort_order'; // Change this to the actual column name representing the sort order + Schema::table( $table, function ( Blueprint $table ) use ( $sortColumn ) { + $table->integer( $sortColumn )->unsigned()->default( 0 ); + } ); - DB::table($table) - ->update([$sortColumn => DB::raw('id')]); + DB::table( $table ) + ->update( [ $sortColumn => DB::raw( 'id' ) ] ); - $sortOrder++; // Increment the sort order for the next table - } } } diff --git a/src/Commands/FilamentSortOrderCommand.php b/src/Commands/FilamentSortOrderCommand.php deleted file mode 100644 index c0b4e87..0000000 --- a/src/Commands/FilamentSortOrderCommand.php +++ /dev/null @@ -1,19 +0,0 @@ -comment('All done'); - - return self::SUCCESS; - } -}