diff --git a/app/Http/Controllers/admin/Catalog/DirectionController.php b/app/Http/Controllers/admin/Catalog/DirectionController.php index 10f6d9a..1c1fe6a 100644 --- a/app/Http/Controllers/admin/Catalog/DirectionController.php +++ b/app/Http/Controllers/admin/Catalog/DirectionController.php @@ -25,13 +25,19 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; use Maatwebsite\Excel\Facades\Excel; +use Spatie\QueryBuilder\AllowedFilter; +use Spatie\QueryBuilder\QueryBuilder; class DirectionController extends Controller { public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application { - $directions = Direction::all()->sortBy('created_at', SORT_REGULAR, true); - return view('admin.catalog.direction.index', compact('directions')); + $directions = QueryBuilder::for(Direction::class) + ->allowedFilters('name') + ->orderBy('id', 'desc')->get(); +// $directions = Direction::all()->sortBy('created_at', SORT_REGULAR, true); + $filter = $request->filter ?? null; + return view('admin.catalog.direction.index', compact('directions', 'filter')); } public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application diff --git a/composer.json b/composer.json index 7d1921e..444180c 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "license": "MIT", "require": { "php": "^8", + "ext-zip": "*", "fakerphp/faker": "^1.23.1", "guzzlehttp/guzzle": "^7.8.1", "imangazaliev/didom": "^2.0.1", @@ -20,8 +21,8 @@ "league/flysystem": "^3.25.0", "maatwebsite/excel": "^3.1.55", "rap2hpoutre/laravel-log-viewer": "^2.3", - "twbs/bootstrap": "5.2.3", - "ext-zip": "*" + "spatie/laravel-query-builder": "^5.8", + "twbs/bootstrap": "5.2.3" }, "require-dev": { "laravel/breeze": "^1.29.1", diff --git a/composer.lock b/composer.lock index 3e1a79a..3253cc0 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": "d5970627f595d4d501a76767ce6e8dae", + "content-hash": "7430aa832d42dad89f7314c9c96e0023", "packages": [ { "name": "brick/math", @@ -4015,6 +4015,139 @@ }, "time": "2023-02-15T07:36:34+00:00" }, + { + "name": "spatie/laravel-package-tools", + "version": "1.16.3", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-package-tools.git", + "reference": "59db18c2e20d49a0b6d447bb1c654f6c123beb9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/59db18c2e20d49a0b6d447bb1c654f6c123beb9e", + "reference": "59db18c2e20d49a0b6d447bb1c654f6c123beb9e", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^9.28|^10.0|^11.0", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.5", + "orchestra/testbench": "^7.7|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.5.24", + "spatie/pest-plugin-test-time": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\LaravelPackageTools\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Tools for creating Laravel packages", + "homepage": "https://github.com/spatie/laravel-package-tools", + "keywords": [ + "laravel-package-tools", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-package-tools/issues", + "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.3" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2024-03-07T07:35:57+00:00" + }, + { + "name": "spatie/laravel-query-builder", + "version": "5.8.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-query-builder.git", + "reference": "8d8b527a68d4651b7860d9993a33b8d4774a9d72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-query-builder/zipball/8d8b527a68d4651b7860d9993a33b8d4774a9d72", + "reference": "8d8b527a68d4651b7860d9993a33b8d4774a9d72", + "shasum": "" + }, + "require": { + "illuminate/database": "^10.0|^11.0", + "illuminate/http": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", + "php": "^8.2", + "spatie/laravel-package-tools": "^1.11" + }, + "require-dev": { + "ext-json": "*", + "mockery/mockery": "^1.4", + "orchestra/testbench": "^7.0|^8.0", + "pestphp/pest": "^2.0", + "spatie/invade": "^2.0", + "spatie/laravel-ray": "^1.28" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\QueryBuilder\\QueryBuilderServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\QueryBuilder\\": "src", + "Spatie\\QueryBuilder\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alex Vanderbist", + "email": "alex@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Easily build Eloquent queries from API requests", + "homepage": "https://github.com/spatie/laravel-query-builder", + "keywords": [ + "laravel-query-builder", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-query-builder/issues", + "source": "https://github.com/spatie/laravel-query-builder" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + } + ], + "time": "2024-02-06T20:07:16+00:00" + }, { "name": "symfony/console", "version": "v6.4.4", diff --git a/resources/views/admin/catalog/direction/index.blade.php b/resources/views/admin/catalog/direction/index.blade.php index f5e652c..2a0b7a2 100644 --- a/resources/views/admin/catalog/direction/index.blade.php +++ b/resources/views/admin/catalog/direction/index.blade.php @@ -9,6 +9,16 @@

+
+
+ {{Form::open(['route' => 'directions.index', 'method' => 'GET'])}} + {{Form::text('filter[name]', $filter['name'] ?? null, ['placeholder' => 'Введите название направления', 'class' => 'form-control'])}} +
+
+ {{Form::submit('Найти', ['class' => 'btn btn-primary'])}} + {{Form::close()}} +
+