act-training / query-builder
A drop in query builder for Laravel models.
Installs: 2 611
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 2
Language:Blade
Requires
- php: ^8.2
- livewire/livewire: ^v3.2.6
- ryangjchandler/blade-tabler-icons: ^2.1
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^v1.12.0
- nunomaduro/collision: ^v8.4.0
- nunomaduro/larastan: ^v2.9.8
- orchestra/testbench: ^9.0
- pestphp/pest: ^v3.2.2
- pestphp/pest-plugin-arch: ^v3.0.0
- pestphp/pest-plugin-laravel: ^v3.0.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-11-07 10:14:21 UTC
README
Add a query builder and report table for youir models.
Installation
You can install the package via composer:
composer require act-training/query-builder
Optionally, you can publish the views using
php artisan vendor:publish --tag="query-builder-views"
Usage
Models should use the AppliesCriteria trait.
class User extends Authenticatable { use AppliesCriteria; ... }
Create a Livewire component and make sure it extends QueryBuilder.
<?php namespace App\Http\Livewire; use ACTTraining\QueryBuilder\QueryBuilder;use ACTTraining\QueryBuilder\Support\Columns\BooleanColumn;use ACTTraining\QueryBuilder\Support\Columns\Column;use ACTTraining\QueryBuilder\Support\Columns\DateColumn;use ACTTraining\QueryBuilder\Support\Conditions\BooleanCondition;use ACTTraining\QueryBuilder\Support\Conditions\DateCondition;use ACTTraining\QueryBuilder\Support\Conditions\TextCondition;use App\Models\Employee;use Illuminate\Database\Eloquent\Builder; class EmployeesReport extends QueryBuilder { public function config(): void { $this ->enableQueryBuilder() ->rowClickable(false); } public function columns(): array { return [ Column::make('Name', 'full_name') ->component('columns.common.title') ->sortable(), Column::make('Job Title', 'contract.job.name'), Column::make('Location', 'contract.location.name'), BooleanColumn::make('Line Manager', 'contract.line_manager') ->hideIf(false) ->justify('center'), DateColumn::make('Start Date', 'contract.start_date') ->humanDiff() ->justify('right'), ]; } public function conditions(): array { return [ TextCondition::make('Name', 'full_name'), TextCondition::make('Job Title', 'contract.job.name'), BooleanCondition::make('Line Manager', 'contract.line_manager'), TextCondition::make('Location', 'contract.location.name'), DateCondition::make('Start Date', 'contract.start_date'), ]; } public function query(): Builder { return Employee::query()->with(['contract', 'contract.job', 'contract.location']); } public function rowClick($row): void { $this->dispatchBrowserEvent('notify', ['content' => 'The row was clicked', 'type' => 'success']); } }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.