add queryBuilder and add filter to name for Direction

This commit is contained in:
aslan 2024-03-18 14:41:12 +03:00
parent 9fcd049173
commit 16785b5698
4 changed files with 155 additions and 5 deletions

View File

@ -25,13 +25,19 @@ use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Facades\Excel; use Maatwebsite\Excel\Facades\Excel;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\QueryBuilder;
class DirectionController extends Controller class DirectionController extends Controller
{ {
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{ {
$directions = Direction::all()->sortBy('created_at', SORT_REGULAR, true); $directions = QueryBuilder::for(Direction::class)
return view('admin.catalog.direction.index', compact('directions')); ->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 public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application

View File

@ -9,6 +9,7 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": "^8", "php": "^8",
"ext-zip": "*",
"fakerphp/faker": "^1.23.1", "fakerphp/faker": "^1.23.1",
"guzzlehttp/guzzle": "^7.8.1", "guzzlehttp/guzzle": "^7.8.1",
"imangazaliev/didom": "^2.0.1", "imangazaliev/didom": "^2.0.1",
@ -20,8 +21,8 @@
"league/flysystem": "^3.25.0", "league/flysystem": "^3.25.0",
"maatwebsite/excel": "^3.1.55", "maatwebsite/excel": "^3.1.55",
"rap2hpoutre/laravel-log-viewer": "^2.3", "rap2hpoutre/laravel-log-viewer": "^2.3",
"twbs/bootstrap": "5.2.3", "spatie/laravel-query-builder": "^5.8",
"ext-zip": "*" "twbs/bootstrap": "5.2.3"
}, },
"require-dev": { "require-dev": {
"laravel/breeze": "^1.29.1", "laravel/breeze": "^1.29.1",

135
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "d5970627f595d4d501a76767ce6e8dae", "content-hash": "7430aa832d42dad89f7314c9c96e0023",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -4015,6 +4015,139 @@
}, },
"time": "2023-02-15T07:36:34+00:00" "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", "name": "symfony/console",
"version": "v6.4.4", "version": "v6.4.4",

View File

@ -9,6 +9,16 @@
</div> </div>
<br> <br>
<br> <br>
<div class="row">
<div class="col-3">
{{Form::open(['route' => 'directions.index', 'method' => 'GET'])}}
{{Form::text('filter[name]', $filter['name'] ?? null, ['placeholder' => 'Введите название направления', 'class' => 'form-control'])}}
</div>
<div class="col">
{{Form::submit('Найти', ['class' => 'btn btn-primary'])}}
{{Form::close()}}
</div>
</div>
<table class="table"> <table class="table">
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left"> <thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
<tr> <tr>