diff --git a/app/Filament/Resources/PeoplesChoiceResource.php b/app/Filament/Resources/PeoplesChoiceResource.php index ea4092f..353aa08 100644 --- a/app/Filament/Resources/PeoplesChoiceResource.php +++ b/app/Filament/Resources/PeoplesChoiceResource.php @@ -33,8 +33,9 @@ class PeoplesChoiceResource extends Resource ->schema([ Select::make('vehicle') ->label('Vehicle') - ->options(Vehicles::all()->pluck('owner', 'id')->sortBy('owner')) - ->searchable(), + ->options(Vehicles::all()->pluck('owner', 'id')) + ->searchable() + ->orderable('owner'), TextInput::make('pc_count'), ]); } diff --git a/app/Models/Vehicles.php b/app/Models/Vehicles.php index adeeb65..f14712f 100644 --- a/app/Models/Vehicles.php +++ b/app/Models/Vehicles.php @@ -3,41 +3,51 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Spatie\EloquentSortable\Sortable; +use Spatie\EloquentSortable\SortableTrait; -class Vehicles extends Model +class Vehicles extends Model implements Sortable { - protected $table = 'vehicles'; - protected $fillable = [ - 'year', - 'make', - 'model', - 'type', - 'doNotJudge', - 'owner' - ]; + use SortableTrait; + + public $sortable = [ + 'order_column_name' => 'owner', + 'sort_when_creating' => true, + ]; - protected $dates = [ - 'created_at', - 'updated_at' - ]; + protected $table = 'vehicles'; - public function vehicleType() - { - return $this->belongsTo('App\Models\CarShowCategory', 'type', 'id'); - } + protected $fillable = [ + 'year', + 'make', + 'model', + 'type', + 'doNotJudge', + 'owner' + ]; - public function vehicleOwner() - { - return $this->belongsTo('App\Models\Bidders', 'owner', 'bidder_assigned_number'); - } + protected $dates = [ + 'created_at', + 'updated_at' + ]; - public function vehicleScores() - { - return $this->hasMany('App\Models\VechicleScores', 'id', 'vehicle'); - } + public function vehicleType() + { + return $this->belongsTo('App\Models\CarShowCategory', 'type', 'id'); + } - public function CarShowWinner() - { - return $this->belongsTo('App\Models\CarShowWinner', 'id', 'vehicle'); - } + public function vehicleOwner() + { + return $this->belongsTo('App\Models\Bidders', 'owner', 'bidder_assigned_number'); + } + + public function vehicleScores() + { + return $this->hasMany('App\Models\VechicleScores', 'id', 'vehicle'); + } + + public function CarShowWinner() + { + return $this->belongsTo('App\Models\CarShowWinner', 'id', 'vehicle'); + } } diff --git a/composer.json b/composer.json index 590c99d..23620ce 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "filament/filament": "^2.0", "laravel/framework": "^9.0", "laravel/tinker": "^2.0", - "laravel/ui": "^3.0" + "laravel/ui": "^3.0", + "spatie/eloquent-sortable": "^4.0" }, "require-dev": { "barryvdh/laravel-debugbar": "^3.7", diff --git a/composer.lock b/composer.lock index 95608cd..4e5c701 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c45f3039cd29758426fcc94f942f94f5", + "content-hash": "746d38f8fb6ae9be134c6ba49f0c1273", "packages": [ { "name": "akaunting/laravel-money", @@ -3554,6 +3554,79 @@ ], "time": "2021-02-11T11:37:01+00:00" }, + { + "name": "spatie/eloquent-sortable", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/eloquent-sortable.git", + "reference": "64a3365c0d5a7b4a1837b2f29d01ee4c578c416a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/eloquent-sortable/zipball/64a3365c0d5a7b4a1837b2f29d01ee4c578c416a", + "reference": "64a3365c0d5a7b4a1837b2f29d01ee4c578c416a", + "shasum": "" + }, + "require": { + "illuminate/database": "^8.0|^9.0", + "illuminate/support": "^8.0|^9.0", + "php": "^8.0", + "spatie/laravel-package-tools": "^1.9" + }, + "require-dev": { + "orchestra/testbench": "^6.0|^7.0", + "phpunit/phpunit": "^9.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\EloquentSortable\\EloquentSortableServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\EloquentSortable\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be" + } + ], + "description": "Sortable behaviour for eloquent models", + "homepage": "https://github.com/spatie/eloquent-sortable", + "keywords": [ + "behaviour", + "eloquent", + "laravel", + "model", + "sort", + "sortable" + ], + "support": { + "issues": "https://github.com/spatie/eloquent-sortable/issues", + "source": "https://github.com/spatie/eloquent-sortable/tree/4.0.1" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2022-01-21T08:32:41+00:00" + }, { "name": "spatie/laravel-package-tools", "version": "1.12.1", diff --git a/config/eloquent-sortable.php b/config/eloquent-sortable.php new file mode 100644 index 0000000..fa57821 --- /dev/null +++ b/config/eloquent-sortable.php @@ -0,0 +1,14 @@ + 'order_column', + + /* + * Define if the models should sort when creating. + * When true, the package will automatically assign the highest order number to a new mode + */ + 'sort_when_creating' => true, +];