Skip to content

Commit

Permalink
Merge pull request #22 from threeel/main
Browse files Browse the repository at this point in the history
Clean up
  • Loading branch information
ibrahimBougaoua authored Sep 24, 2024
2 parents d974a22 + dd8b715 commit 269886d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 36 deletions.
16 changes: 10 additions & 6 deletions config/filament-sort-order.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?php

// config for IbrahimBougaoua/FilamentSortOrder
// You can incorporate additional tables by appending "table{number}" as an illustration.
// 'table1' =>'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',
];
19 changes: 8 additions & 11 deletions database/migrations/create_filament_sort_order_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
19 changes: 0 additions & 19 deletions src/Commands/FilamentSortOrderCommand.php

This file was deleted.

0 comments on commit 269886d

Please sign in to comment.