diff --git a/app/Http/Controllers/Search/GameSystemSearchController.php b/app/Http/Controllers/Search/GameSystemSearchController.php index 7f03d8952a..7fccf2e2e3 100644 --- a/app/Http/Controllers/Search/GameSystemSearchController.php +++ b/app/Http/Controllers/Search/GameSystemSearchController.php @@ -20,6 +20,7 @@ public function index(Campaign $campaign): JsonResponse /** @var GameSystem[] $systems */ $systems = GameSystem::where('name', 'like', '%' . request()->get('q') . '%') ->withCount('campaignSystem')->orderBy('campaign_system_count', 'desc') + ->orderBy('name', 'asc') ->limit(20) ->get(); @@ -33,7 +34,7 @@ public function index(Campaign $campaign): JsonResponse } return response()->json( - $formatted + $formatted ?? [] ); } } diff --git a/app/Models/GameSystem.php b/app/Models/GameSystem.php index 5152e7f159..5d65bee83a 100644 --- a/app/Models/GameSystem.php +++ b/app/Models/GameSystem.php @@ -4,6 +4,10 @@ use Illuminate\Database\Eloquent\Model; +/** + * @property int $id + * @property string $name + */ class GameSystem extends Model { public function campaignSystem() diff --git a/app/Models/Scopes/CampaignScopes.php b/app/Models/Scopes/CampaignScopes.php index d13a636bc4..272420fdc9 100644 --- a/app/Models/Scopes/CampaignScopes.php +++ b/app/Models/Scopes/CampaignScopes.php @@ -137,6 +137,7 @@ public function scopeFront(Builder $query, int $sort = null): Builder } $defaultSort = $sort == 1 ? 'follower' : 'visible_entity_count'; $query + ->with('systems') ->where('is_hidden', 0) ->orderBy($defaultSort, 'desc') ->orderBy('name'); @@ -168,7 +169,9 @@ public function scopeFilterPublic(Builder $query, array $options): Builder ->select('campaigns.*') ->leftJoin('campaign_system as cs', function ($join) { $join->on('cs.campaign_id', '=', 'campaigns.id'); - })->whereIn('cs.system_id', $system)->distinct(); + }) + ->whereIn('cs.system_id', $system) + ->distinct(); } $boosted = Arr::get($options, 'is_boosted'); if ($boosted === "1") { diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index ac0b4bfd0b..92070b7928 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -17,6 +17,7 @@ public function run() $this->call(EntityTypesTableSeeder::class); $this->call(PresetTypeTableSeeder::class); //$this->call(RpgSystemsTableSeeder::class); + $this->call(GameSystemSeeder::class); $this->call(ThemesTableSeeder::class); $this->call(RolesTableSeeder::class); $this->call(VisibilitiesTableSeeder::class); diff --git a/database/seeders/GameSystemSeeder.php b/database/seeders/GameSystemSeeder.php new file mode 100644 index 0000000000..ca57dbd0d3 --- /dev/null +++ b/database/seeders/GameSystemSeeder.php @@ -0,0 +1,85 @@ + $name, + ]); + if ($genre->exists) { + continue; + } + $genre->fill([ + 'name' => $name, + ])->save(); + } + } +}