dependencies-upgrade

This commit is contained in:
RafficMohammed
2023-01-08 02:20:59 +05:30
parent 7870479b18
commit 49021a4497
1711 changed files with 74994 additions and 70803 deletions

View File

@@ -8,6 +8,139 @@
### [Unreleased]
### [v9.21.2] - 2022-07-12
- Fix HasOneThrough (added tests) #2816
- Fix #2738
### [v9.21.1] - 2022-06-22
- Fix sorting and pagination on empty records #2803
### [v9.21.0] - 2022-06-21
- Add support for dependency injection when using closure. #2521
### [v9.20.0] - 2022-05-09
- Added orthogonal sort and filter for collection #2380
### [v9.19.2] - 2022-04-07
- Changed PHPDocs to have the most specific class as their super return type #2771
### [v9.19.1] - 2022-03-05
- Fix Formatter::format() doc block.
- Fix `are` Word in Description #2743
- Update README #2735
### [v9.19.0] - 2022-01-18
- Support for Laravel 9 #2727
- Don't trash the exception stack trace (#2714) #2724
### [v9.18.2] - 2021-06-28
- Return empty string for null request keyword #2700
### [v9.18.1] - 2021-06-28
- Query with subqueries exception fix. #2642
### [v9.18.0] - 2021-04-16
- Improve count performance for simple queries. #2616
- Fixes #1928
- Make prepareCountQuery() public so its easy to test.
### [v9.17.4] - 2021-04-15
- Revert changes on count. #2614
- Fix #2613
- Reverts: #2611 and #2612
### [v9.17.3] - 2021-04-14
- Fix the regression when using a having condition in a query. #2612
- Fix #1928
- Code cleanup in QueryDataTable class #2606
### [v9.17.2] - 2021-04-12
- Remove unnecessary wrap to avoid performance issues #2608.
- Fixes #1928.
### [v9.17.1] - 2021-03-23
- Fix morph relation support with multi level relations. #2588 #2590
- Fix tests and doc blocks. #2586
- Fixes #2587, #2589, #2580
### [v9.17.0] - 2021-03-19
- feat(relations): add partial polymorphic support [#2580]
### [v9.16.0] - 2021-03-19
- Add set multi term on runtime [#2585]
### [v9.15.2] - 2020-12-04
- Remove raw sql when using regex and wrap the column name.
### [v9.15.1] - 2020-12-03
- Fix search pane builder instance when using eloquent. [#2540]
### [v9.15.0] - 2020-11-28
- PHP8 support [#2536]
### [v9.14.2] - 2020-11-27
- Fix PHP8 error, method exists now throws an exception if the first argument is not string|object [#2535]
- Fixes [#2534]
### [v9.14.1] - 2020-11-11
- Fix resolution of custom search pane query builder. [#2513]
### [v9.14.0] - 2020-11-03
- Add column formatter. [#2193]
- Fix [yajra/laravel-datatables-editor#33](https://github.com/yajra/laravel-datatables-editor/issues/33)
### [v9.13.0] - 2020-10-31
- Add support for search panes. [#2475]
- Fix [#2463], [#2471]
### [v9.12.0] - 2020-10-31
- Add disable ordering via orderColumn. [#2481], credits to [@gredimano]
- Fix [#1953]
### [v9.11.1] - 2020-10-06
- Use simple numeric sorting when dealing with numeric values [#2478], credits to [@miken32]
- Fix [#1934].
### [v9.11.0] - 2020-09-09
- Add support for Laravel 8. [#2457] by [@lloricode]
### [v9.10.2] - 2020-06-17
- Escape row in data processor also accepts Htmlable [#2414], credits to [@edwwaarrdd].
### [v9.10.1] - 2020-05-30
- Fix type casting issue [#2399], credits to [@ehsanrasta].
- Fix [#1975] , [#1747].
- Fix issue with non-existing variables/attributes on Collection. [#2391], credits to [@mgralikowski].
- Add laravel missing versions on every docs [#2382], credits to [@lloricode].
### [v9.10.0] - 2020-04-23
- Add support for HasOneThrough [#2368], credits to [@warlof]
@@ -374,7 +507,33 @@ return (new CollectionDataTable(User::all())->toJson();
- Fix orderColumn api where related tables are not joined.
- Fix nested with relation search and sort function.
[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v9.10.0...9.0
[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v9.21.2...9.0
[v9.21.2]: https://github.com/yajra/laravel-datatables/compare/v9.21.1...v9.21.2
[v9.21.0]: https://github.com/yajra/laravel-datatables/compare/v9.20.0...v9.21.0
[v9.20.0]: https://github.com/yajra/laravel-datatables/compare/v9.19.1...v9.20.0
[v9.19.1]: https://github.com/yajra/laravel-datatables/compare/v9.19.1...v9.19.1
[v9.19.0]: https://github.com/yajra/laravel-datatables/compare/v9.18.2...v9.19.0
[v9.18.2]: https://github.com/yajra/laravel-datatables/compare/v9.18.1...v9.18.2
[v9.18.1]: https://github.com/yajra/laravel-datatables/compare/v9.18.0...v9.18.1
[v9.18.0]: https://github.com/yajra/laravel-datatables/compare/v9.17.4...v9.18.0
[v9.17.4]: https://github.com/yajra/laravel-datatables/compare/v9.17.3...v9.17.4
[v9.17.3]: https://github.com/yajra/laravel-datatables/compare/v9.17.2...v9.17.3
[v9.17.2]: https://github.com/yajra/laravel-datatables/compare/v9.17.1...v9.17.2
[v9.17.1]: https://github.com/yajra/laravel-datatables/compare/v9.17.0...v9.17.1
[v9.17.0]: https://github.com/yajra/laravel-datatables/compare/v9.16.0...v9.17.0
[v9.16.0]: https://github.com/yajra/laravel-datatables/compare/v9.15.2...v9.16.0
[v9.15.2]: https://github.com/yajra/laravel-datatables/compare/v9.15.1...v9.15.2
[v9.15.1]: https://github.com/yajra/laravel-datatables/compare/v9.15.0...v9.15.1
[v9.15.0]: https://github.com/yajra/laravel-datatables/compare/v9.14.2...v9.15.0
[v9.14.2]: https://github.com/yajra/laravel-datatables/compare/v9.14.1...v9.14.2
[v9.14.1]: https://github.com/yajra/laravel-datatables/compare/v9.14.0...v9.14.1
[v9.14.0]: https://github.com/yajra/laravel-datatables/compare/v9.13.0...v9.14.0
[v9.13.0]: https://github.com/yajra/laravel-datatables/compare/v9.12.0...v9.13.0
[v9.12.0]: https://github.com/yajra/laravel-datatables/compare/v9.11.1...v9.12.0
[v9.11.1]: https://github.com/yajra/laravel-datatables/compare/v9.11.0...v9.11.1
[v9.11.0]: https://github.com/yajra/laravel-datatables/compare/v9.10.2...v9.11.0
[v9.10.2]: https://github.com/yajra/laravel-datatables/compare/v9.10.1...v9.10.2
[v9.10.1]: https://github.com/yajra/laravel-datatables/compare/v9.10.0...v9.10.1
[v9.10.0]: https://github.com/yajra/laravel-datatables/compare/v9.9.0...v9.10.0
[v9.9.0]: https://github.com/yajra/laravel-datatables/compare/v9.8.0...v9.9.0
[v9.8.0]: https://github.com/yajra/laravel-datatables/compare/v9.7.2...v9.8.0
@@ -508,7 +667,22 @@ return (new CollectionDataTable(User::all())->toJson();
[#2263]: https://github.com/yajra/laravel-datatables/pull/2263
[#2332]: https://github.com/yajra/laravel-datatables/pull/2332
[#2368]: https://github.com/yajra/laravel-datatables/pull/2368
[#2399]: https://github.com/yajra/laravel-datatables/pull/2399
[#2391]: https://github.com/yajra/laravel-datatables/pull/2391
[#2382]: https://github.com/yajra/laravel-datatables/pull/2382
[#2414]: https://github.com/yajra/laravel-datatables/pull/2414
[#2478]: https://github.com/yajra/laravel-datatables/pull/2478
[#2481]: https://github.com/yajra/laravel-datatables/pull/2481
[#2475]: https://github.com/yajra/laravel-datatables/pull/2475
[#2193]: https://github.com/yajra/laravel-datatables/pull/2193
[#2513]: https://github.com/yajra/laravel-datatables/pull/2513
[#2535]: https://github.com/yajra/laravel-datatables/pull/2535
[#2536]: https://github.com/yajra/laravel-datatables/pull/2536
[#2540]: https://github.com/yajra/laravel-datatables/pull/2540
[#2585]: https://github.com/yajra/laravel-datatables/pull/2585
[#2580]: https://github.com/yajra/laravel-datatables/pull/2580
[#1934]: https://github.com/yajra/laravel-datatables/issues/1934
[#2091]: https://github.com/yajra/laravel-datatables/issues/2091
[#2058]: https://github.com/yajra/laravel-datatables/issues/2058
[#1626]: https://github.com/yajra/laravel-datatables/issues/1626
@@ -545,6 +719,12 @@ return (new CollectionDataTable(User::all())->toJson();
[#1822]: https://github.com/yajra/laravel-datatables/issues/1822
[#1738]: https://github.com/yajra/laravel-datatables/issues/1738
[#2202]: https://github.com/yajra/laravel-datatables/issues/2202
[#1975]: https://github.com/yajra/laravel-datatables/issues/1975
[#1747]: https://github.com/yajra/laravel-datatables/issues/1747
[#1953]: https://github.com/yajra/laravel-datatables/issues/1953
[#2463]: https://github.com/yajra/laravel-datatables/issues/2463
[#2471]: https://github.com/yajra/laravel-datatables/issues/2471
[#2534]: https://github.com/yajra/laravel-datatables/issues/2534
[laravel-datatables-fractal]: https://github.com/yajra/laravel-datatables-fractal
@@ -583,3 +763,8 @@ return (new CollectionDataTable(User::all())->toJson();
[@imTigger]: https://github.com/imTigger
[@barryvdh]: https://github.com/barryvdh
[@warlof]: https://github.com/warlof
[@ehsanrasta]: https://github.com/ehsanrasta
[@mgralikowski]: https://github.com/mgralikowski
[@edwwaarrdd]: https://github.com/edwwaarrdd
[@miken32]: https://github.com/miken32
[@gredimano]: https://github.com/gredimano

View File

@@ -1,22 +1,64 @@
# Contributor Code of Conduct
# Contributor Covenant Code of Conduct
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
Examples of unacceptable behavior by participants include:
## Our Standards
Examples of behavior that contributes to a positive environment for our community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community
* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
* Other unethical or unprofessional conduct.
* Publishing others private information, such as a physical or email address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community in a direct capacity. Personal views, beliefs and values of individuals do not necessarily reflect those of the organisation or affiliated individuals and organisations.
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
## Scope
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
Community Impact: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
Consequence: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
### 2. Warning
Community Impact: A violation through a single incident or series of actions.
Consequence: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
### 3. Temporary Ban
Community Impact: A serious violation of community standards, including sustained inappropriate behavior.
Consequence: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
Community Impact: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
Consequence: A permanent ban from any sort of public interaction within the community.
## Attribution
This Code of Conduct is adapted from the Contributor Covenant, version 2.1, available at https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
Community Impact Guidelines were inspired by Mozillas code of conduct enforcement ladder.
For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.

View File

@@ -1,6 +1,6 @@
(The MIT License)
Copyright (c) 2013-2019 Arjay Angeles <aqangeles@gmail.com>
Copyright (c) 2013-2021 Arjay Angeles <aqangeles@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -1,13 +1,13 @@
# jQuery DataTables API for Laravel 4|5|6
# jQuery DataTables API for Laravel 4|5|6|7|8|9
[![Join the chat at https://gitter.im/yajra/laravel-datatables](https://badges.gitter.im/yajra/laravel-datatables.svg)](https://gitter.im/yajra/laravel-datatables?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/yajra)
[![Donate](https://img.shields.io/badge/donate-patreon-blue.svg)](https://www.patreon.com/bePatron?u=4521203)
[![Laravel 4.2|5.x|6.x](https://img.shields.io/badge/Laravel-4.2|5.x-orange.svg)](http://laravel.com)
[![Laravel 4.2|5.x|6|7|8|9](https://img.shields.io/badge/Laravel-4.2|5.x|6|7|8|9-orange.svg)](http://laravel.com)
[![Latest Stable Version](https://img.shields.io/packagist/v/yajra/laravel-datatables-oracle.svg)](https://packagist.org/packages/yajra/laravel-datatables-oracle)
[![Latest Unstable Version](https://poser.pugx.org/yajra/laravel-datatables-oracle/v/unstable.svg)](https://packagist.org/packages/yajra/laravel-datatables-oracle)
[![Build Status](https://travis-ci.org/yajra/laravel-datatables.svg?branch=master)](https://travis-ci.org/yajra/laravel-datatables)
![Build Status](https://github.com/yajra/laravel-datatables-html/workflows/tests/badge.svg)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yajra/laravel-datatables/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yajra/laravel-datatables/?branch=master)
[![Total Downloads](https://poser.pugx.org/yajra/laravel-datatables-oracle/downloads.png)](https://packagist.org/packages/yajra/laravel-datatables-oracle)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://packagist.org/packages/yajra/laravel-datatables-oracle)
@@ -29,8 +29,8 @@ return datatables(User::all())->toJson();
```
## Requirements
- [PHP >= 7.0](http://php.net/)
- [Laravel 5.x|6.x](https://github.com/laravel/framework)
- [PHP >= 7.1](http://php.net/)
- [Laravel 4.2|5.x|6|7|8|9](https://github.com/laravel/framework)
- [jQuery DataTables v1.10.x](http://datatables.net/)
## Documentations
@@ -60,6 +60,8 @@ return datatables(User::all())->toJson();
5.8.x | 9.x
6.x.x | 9.x
7.x.x | 9.x
8.x.x | 9.x
9.x.x | 9.x
## DataTables 8.x Upgrade Guide
There are breaking changes since DataTables v8.x.
@@ -70,7 +72,7 @@ If you are upgrading from v7.x to v8.x, please see [upgrade guide](https://yajra
$ composer require yajra/laravel-datatables-oracle:"~9.0"
```
#### Service Provider & Facade (Optional on Laravel 5.5)
#### Service Provider & Facade (Optional on Laravel 5.5+)
Register provider and facade on your `config/app.php` file.
```php
'providers' => [

View File

@@ -1,6 +1,6 @@
{
"name": "yajra/laravel-datatables-oracle",
"description": "jQuery DataTables API for Laravel 4|5",
"description": "jQuery DataTables API for Laravel 5|6|7|8|9",
"keywords": [
"laravel",
"dataTables",
@@ -14,15 +14,15 @@
}
],
"require": {
"php": "^7.1.3",
"illuminate/database": "5.8.*|^6|^7",
"illuminate/filesystem": "5.8.*|^6|^7",
"illuminate/http": "5.8.*|^6|^7",
"illuminate/support": "5.8.*|^6|^7",
"illuminate/view": "5.8.*|^6|^7"
"php": "^7.1.3|^8",
"illuminate/database": "5.8.*|^6|^7|^8|^9",
"illuminate/filesystem": "5.8.*|^6|^7|^8|^9",
"illuminate/http": "5.8.*|^6|^7|^8|^9",
"illuminate/support": "5.8.*|^6|^7|^8|^9",
"illuminate/view": "5.8.*|^6|^7|^8|^9"
},
"require-dev": {
"orchestra/testbench": "^3.8"
"orchestra/testbench": "^3.8|^4.0|^5.0|^6.0|^7.0"
},
"suggest": {
"yajra/laravel-datatables-buttons": "Plugin for server-side exporting of dataTables.",

View File

@@ -2,9 +2,9 @@
namespace Yajra\DataTables;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
class ApiResourceDataTable extends CollectionDataTable
{
@@ -25,7 +25,7 @@ class ApiResourceDataTable extends CollectionDataTable
/**
* Can the DataTable engine be created with these parameters.
*
* @param mixed $source
* @param mixed $source
* @return bool
*/
public static function canCreate($source)
@@ -36,7 +36,7 @@ class ApiResourceDataTable extends CollectionDataTable
/**
* Factory method, create and return an instance for the DataTable engine.
*
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection $source
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection $source
* @return ApiResourceDataTable|DataTableAbstract
*/
public static function create($source)
@@ -47,7 +47,7 @@ class ApiResourceDataTable extends CollectionDataTable
/**
* CollectionEngine constructor.
*
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection $collection
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection $collection
*/
public function __construct(AnonymousResourceCollection $collection)
{

View File

@@ -2,10 +2,10 @@
namespace Yajra\DataTables;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
class CollectionDataTable extends DataTableAbstract
{
@@ -33,7 +33,7 @@ class CollectionDataTable extends DataTableAbstract
/**
* Can the DataTable engine be created with these parameters.
*
* @param mixed $source
* @param mixed $source
* @return bool
*/
public static function canCreate($source)
@@ -44,7 +44,7 @@ class CollectionDataTable extends DataTableAbstract
/**
* Factory method, create and return an instance for the DataTable engine.
*
* @param array|\Illuminate\Support\Collection $source
* @param array|\Illuminate\Support\Collection $source
* @return CollectionDataTable|DataTableAbstract
*/
public static function create($source)
@@ -59,7 +59,7 @@ class CollectionDataTable extends DataTableAbstract
/**
* CollectionEngine constructor.
*
* @param \Illuminate\Support\Collection $collection
* @param \Illuminate\Support\Collection $collection
*/
public function __construct(Collection $collection)
{
@@ -73,7 +73,7 @@ class CollectionDataTable extends DataTableAbstract
/**
* Serialize collection.
*
* @param mixed $collection
* @param mixed $collection
* @return mixed|null
*/
protected function serialize($collection)
@@ -100,7 +100,7 @@ class CollectionDataTable extends DataTableAbstract
{
$columns = $this->request->get('columns', []);
for ($i = 0, $c = count($columns); $i < $c; $i++) {
$column = $this->getColumnName($i);
$column = $this->getColumnName($i, 'filter');
if (! $this->request->isColumnSearchable($i) || $this->isBlacklisted($column)) {
continue;
@@ -151,7 +151,7 @@ class CollectionDataTable extends DataTableAbstract
/**
* Organizes works.
*
* @param bool $mDataSupport
* @param bool $mDataSupport
* @return \Illuminate\Http\JsonResponse
*/
public function make($mDataSupport = true)
@@ -201,7 +201,7 @@ class CollectionDataTable extends DataTableAbstract
/**
* Revert transformed DT_RowIndex back to it's original values.
*
* @param bool $mDataSupport
* @param bool $mDataSupport
*/
private function revertIndexColumn($mDataSupport)
{
@@ -219,7 +219,7 @@ class CollectionDataTable extends DataTableAbstract
/**
* Perform global search for the given keyword.
*
* @param string $keyword
* @param string $keyword
*/
protected function globalSearch($keyword)
{
@@ -230,8 +230,8 @@ class CollectionDataTable extends DataTableAbstract
$data = $this->serialize($row);
foreach ($this->request->searchableColumnIndex() as $index) {
$column = $this->getColumnName($index);
$value = Arr::get($data, $column);
$column = $this->getColumnName($index, 'sort');
$value = Arr::get($data, $column);
if (! $value || is_array($value)) {
if (! is_numeric($value)) {
continue;
@@ -278,14 +278,14 @@ class CollectionDataTable extends DataTableAbstract
/**
* Get array sorter closure.
*
* @param array $criteria
* @param array $criteria
* @return \Closure
*/
protected function getSorter(array $criteria)
{
$sorter = function ($a, $b) use ($criteria) {
foreach ($criteria as $orderable) {
$column = $this->getColumnName($orderable['column']);
$column = $this->getColumnName($orderable['column'], 'sort');
$direction = $orderable['direction'];
if ($direction === 'desc') {
$first = $b;
@@ -294,10 +294,18 @@ class CollectionDataTable extends DataTableAbstract
$first = $a;
$second = $b;
}
if ($this->config->isCaseInsensitive()) {
$cmp = strnatcasecmp($first[$column], $second[$column]);
if (is_numeric($first[$column] ?? null) && is_numeric($second[$column] ?? null)) {
if ($first[$column] < $second[$column]) {
$cmp = -1;
} elseif ($first[$column] > $second[$column]) {
$cmp = 1;
} else {
$cmp = 0;
}
} elseif ($this->config->isCaseInsensitive()) {
$cmp = strnatcasecmp($first[$column] ?? null, $second[$column] ?? null);
} else {
$cmp = strnatcmp($first[$column], $second[$column]);
$cmp = strnatcmp($first[$column] ?? null, $second[$column] ?? null);
}
if ($cmp != 0) {
return $cmp;
@@ -326,7 +334,7 @@ class CollectionDataTable extends DataTableAbstract
* the FULL dataset the collection was sliced from. It effectively allows the
* collection to be "pre-sliced".
*
* @param int $offset
* @param int $offset
* @return $this
*/
public function setOffset(int $offset)

View File

@@ -29,8 +29,8 @@ interface DataTable
* Set auto filter off and run your own filter.
* Overrides global search.
*
* @param callable $callback
* @param bool $globalSearch
* @param callable $callback
* @param bool $globalSearch
* @return $this
*/
public function filter(callable $callback, $globalSearch = false);
@@ -66,7 +66,7 @@ interface DataTable
/**
* Organizes works.
*
* @param bool $mDataSupport
* @param bool $mDataSupport
* @return \Illuminate\Http\JsonResponse
*/
public function make($mDataSupport = true);

View File

@@ -0,0 +1,13 @@
<?php
namespace Yajra\DataTables\Contracts;
interface Formatter
{
/**
* @param mixed $value
* @param mixed $row
* @return string
*/
public function format($value, $row);
}

View File

@@ -2,23 +2,25 @@
namespace Yajra\DataTables;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Psr\Log\LoggerInterface;
use Illuminate\Http\JsonResponse;
use Yajra\DataTables\Utilities\Helper;
use Illuminate\Support\Traits\Macroable;
use Psr\Log\LoggerInterface;
use Yajra\DataTables\Contracts\DataTable;
use Illuminate\Contracts\Support\Jsonable;
use Yajra\DataTables\Exceptions\Exception;
use Illuminate\Contracts\Support\Arrayable;
use Yajra\DataTables\Contracts\Formatter;
use Yajra\DataTables\Processors\DataProcessor;
use Yajra\DataTables\Utilities\Helper;
/**
* @method DataTableAbstract setTransformer($transformer)
* @method DataTableAbstract setSerializer($transformer)
*
* @property mixed transformer
* @property mixed serializer
*
* @see https://github.com/yajra/laravel-datatables-fractal for transformer related methods.
*/
abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
@@ -145,10 +147,15 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
*/
protected $serializer;
/**
* @var array
*/
protected $searchPanes = [];
/**
* Can the DataTable engine be created with these parameters.
*
* @param mixed $source
* @param mixed $source
* @return bool
*/
public static function canCreate($source)
@@ -159,7 +166,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Factory method, create and return an instance for the DataTable engine.
*
* @param mixed $source
* @param mixed $source
* @return DataTableAbstract
*/
public static function create($source)
@@ -170,9 +177,9 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Add column in collection.
*
* @param string $name
* @param string|callable $content
* @param bool|int $order
* @param string $name
* @param string|callable $content
* @param bool|int $order
* @return $this
*/
public function addColumn($name, $content, $order = false)
@@ -184,6 +191,30 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
return $this;
}
/**
* @param string|array $columns
* @param mixed|\Yajra\DataTables\Contracts\Formatter $formatter
* @return $this
*
* @throws \Exception
*/
public function formatColumn($columns, $formatter)
{
if (is_string($formatter) && class_exists($formatter)) {
$formatter = app($formatter);
}
if (! $formatter instanceof Formatter) {
throw new \Exception('$formatter must be an instance of '. Formatter::class);
}
foreach ((array) $columns as $column) {
$this->addColumn($column . '_formatted', $formatter);
}
return $this;
}
/**
* Add DT row index column on response.
*
@@ -199,8 +230,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Edit column's content.
*
* @param string $name
* @param string|callable $content
* @param string $name
* @param string|callable $content
* @return $this
*/
public function editColumn($name, $content)
@@ -226,7 +257,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Get only selected columns in response.
*
* @param array $columns
* @param array $columns
* @return $this
*/
public function only(array $columns = [])
@@ -239,7 +270,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Declare columns to escape values.
*
* @param string|array $columns
* @param string|array $columns
* @return $this
*/
public function escapeColumns($columns = '*')
@@ -252,7 +283,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Add a makeHidden() to the row object.
*
* @param array $attributes
* @param array $attributes
* @return $this
*/
public function makeHidden(array $attributes = [])
@@ -265,7 +296,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Add a makeVisible() to the row object.
*
* @param array $attributes
* @param array $attributes
* @return $this
*/
public function makeVisible(array $attributes = [])
@@ -279,8 +310,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
* Set columns that should not be escaped.
* Optionally merge the defaults from config.
*
* @param array $columns
* @param bool $merge
* @param array $columns
* @param bool $merge
* @return $this
*/
public function rawColumns(array $columns, $merge = false)
@@ -300,7 +331,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
* Sets DT_RowClass template.
* result: <tr class="output_from_your_template">.
*
* @param string|callable $content
* @param string|callable $content
* @return $this
*/
public function setRowClass($content)
@@ -314,7 +345,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
* Sets DT_RowId template.
* result: <tr id="output_from_your_template">.
*
* @param string|callable $content
* @param string|callable $content
* @return $this
*/
public function setRowId($content)
@@ -327,7 +358,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Set DT_RowData templates.
*
* @param array $data
* @param array $data
* @return $this
*/
public function setRowData(array $data)
@@ -340,8 +371,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Add DT_RowData template.
*
* @param string $key
* @param string|callable $value
* @param string $key
* @param string|callable $value
* @return $this
*/
public function addRowData($key, $value)
@@ -355,7 +386,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
* Set DT_RowAttr templates.
* result: <tr attr1="attr1" attr2="attr2">.
*
* @param array $data
* @param array $data
* @return $this
*/
public function setRowAttr(array $data)
@@ -368,8 +399,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Add DT_RowAttr template.
*
* @param string $key
* @param string|callable $value
* @param string $key
* @param string|callable $value
* @return $this
*/
public function addRowAttr($key, $value)
@@ -382,8 +413,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Append data on json response.
*
* @param mixed $key
* @param mixed $value
* @param mixed $key
* @param mixed $value
* @return $this
*/
public function with($key, $value = '')
@@ -402,8 +433,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Add with query callback value on response.
*
* @param string $key
* @param callable $value
* @param string $key
* @param callable $value
* @return $this
*/
public function withQuery($key, callable $value)
@@ -416,7 +447,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Override default ordering method with a closure callback.
*
* @param callable $closure
* @param callable $closure
* @return $this
*/
public function order(callable $closure)
@@ -429,7 +460,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Update list of columns that is not allowed for search/sort.
*
* @param array $blacklist
* @param array $blacklist
* @return $this
*/
public function blacklist(array $blacklist)
@@ -442,7 +473,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Update list of columns that is allowed for search/sort.
*
* @param string|array $whitelist
* @param string|array $whitelist
* @return $this
*/
public function whitelist($whitelist = '*')
@@ -455,7 +486,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Set smart search config at runtime.
*
* @param bool $state
* @param bool $state
* @return $this
*/
public function smart($state = true)
@@ -468,7 +499,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Set starts_with search config at runtime.
*
* @param bool $state
* @param bool $state
* @return $this
*/
public function startsWithSearch($state = true)
@@ -478,10 +509,23 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
return $this;
}
/**
* Set multi_term search config at runtime.
*
* @param bool $multiTerm
* @return $this
*/
public function setMultiTerm($multiTerm = true)
{
$this->config->set('datatables.search.multi_term', $multiTerm);
return $this;
}
/**
* Set total records manually.
*
* @param int $total
* @param int $total
* @return $this
*/
public function setTotalRecords($total)
@@ -494,7 +538,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Set filtered records manually.
*
* @param int $total
* @param int $total
* @return $this
*/
public function setFilteredRecords($total)
@@ -519,7 +563,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Push a new column name to blacklist.
*
* @param string $column
* @param string $column
* @return $this
*/
public function pushToBlacklist($column)
@@ -534,7 +578,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Check if column is blacklisted.
*
* @param string $column
* @param string $column
* @return bool
*/
protected function isBlacklisted($column)
@@ -593,8 +637,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
* Set auto filter off and run your own filter.
* Overrides global search.
*
* @param callable $callback
* @param bool $globalSearch
* @param callable $callback
* @param bool $globalSearch
* @return $this
*/
public function filter(callable $callback, $globalSearch = false)
@@ -619,7 +663,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Convert the object to its JSON representation.
*
* @param int $options
* @param int $options
* @return \Illuminate\Http\JsonResponse
*/
public function toJson($options = 0)
@@ -657,9 +701,18 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
}
$this->columnSearch();
$this->searchPanesSearch();
$this->filteredRecords = $this->isFilterApplied ? $this->filteredCount() : $this->totalRecords;
}
/**
* Perform search using search pane values.
*/
protected function searchPanesSearch()
{
// Add support for search pane.
}
/**
* Perform global search.
*
@@ -682,7 +735,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
* Perform multi-term search by splitting keyword into
* individual words and searches for each of them.
*
* @param string $keyword
* @param string $keyword
*/
protected function smartGlobalSearch($keyword)
{
@@ -698,7 +751,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Perform global search for the given keyword.
*
* @param string $keyword
* @param string $keyword
*/
abstract protected function globalSearch($keyword);
@@ -717,8 +770,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Transform output.
*
* @param mixed $results
* @param mixed $processed
* @param mixed $results
* @param mixed $processed
* @return array
*/
protected function transform($results, $processed)
@@ -737,8 +790,8 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Get processed data.
*
* @param mixed $results
* @param bool $object
* @param mixed $results
* @param bool $object
* @return array
*/
protected function processResults($results, $object = false)
@@ -756,7 +809,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Render json response.
*
* @param array $data
* @param array $data
* @return \Illuminate\Http\JsonResponse
*/
protected function render(array $data)
@@ -772,6 +825,10 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
$output = $this->showDebugger($output);
}
foreach ($this->searchPanes as $column => $searchPane) {
$output['searchPanes']['options'][$column] = $searchPane['options'];
}
return new JsonResponse(
$output,
200,
@@ -783,7 +840,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Attach custom with meta on response.
*
* @param array $data
* @param array $data
* @return array
*/
protected function attachAppends(array $data)
@@ -794,7 +851,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Append debug parameters on output.
*
* @param array $output
* @param array $output
* @return array
*/
protected function showDebugger(array $output)
@@ -807,8 +864,9 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Return an error json response.
*
* @param \Exception $exception
* @param \Exception $exception
* @return \Illuminate\Http\JsonResponse
*
* @throws \Yajra\DataTables\Exceptions\Exception
*/
protected function errorResponse(\Exception $exception)
@@ -817,7 +875,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
$debug = $this->config->get('app.debug');
if ($error === 'throw' || (! $error && ! $debug)) {
throw new Exception($exception->getMessage(), $code = 0, $exception);
throw $exception;
}
$this->getLogger()->error($exception);
@@ -846,7 +904,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Set monolog/logger instance.
*
* @param \Psr\Log\LoggerInterface $logger
* @param \Psr\Log\LoggerInterface $logger
* @return $this
*/
public function setLogger(LoggerInterface $logger)
@@ -859,7 +917,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Setup search keyword.
*
* @param string $value
* @param string $value
* @return string
*/
protected function setupKeyword($value)
@@ -881,13 +939,14 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Get column name to be use for filtering and sorting.
*
* @param int $index
* @param bool $wantsAlias
* @param int $index
* @param string|null $type
* @param bool $wantsAlias
* @return string
*/
protected function getColumnName($index, $wantsAlias = false)
protected function getColumnName($index, $type = null, $wantsAlias = false)
{
$column = $this->request->columnName($index);
$column = $this->request->columnName($index, $type);
// DataTables is using make(false)
if (is_numeric($column)) {
@@ -904,7 +963,7 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
/**
* Get column name by order column index.
*
* @param int $index
* @param int $index
* @return string
*/
protected function getColumnNameByIndex($index)
@@ -924,4 +983,26 @@ abstract class DataTableAbstract implements DataTable, Arrayable, Jsonable
{
return 'id';
}
/**
* Add a search pane options on response.
*
* @param string $column
* @param mixed $options
* @param callable|null $builder
* @return $this
*/
public function searchPane($column, $options, callable $builder = null)
{
$options = value($options);
if ($options instanceof Arrayable) {
$options = $options->toArray();
}
$this->searchPanes[$column]['options'] = $options;
$this->searchPanes[$column]['builder'] = $builder;
return $this;
}
}

View File

@@ -26,8 +26,9 @@ class DataTables
* Make a DataTable instance from source.
* Alias of make for backward compatibility.
*
* @param mixed $source
* @param mixed $source
* @return mixed
*
* @throws \Exception
*/
public static function of($source)
@@ -38,8 +39,9 @@ class DataTables
/**
* Make a DataTable instance from source.
*
* @param mixed $source
* @param mixed $source
* @return mixed
*
* @throws \Exception
*/
public static function make($source)
@@ -85,6 +87,7 @@ class DataTables
/**
* @deprecated Please use query() instead, this method will be removed in a next version.
*
* @param $builder
* @return QueryDataTable
*/
@@ -96,8 +99,8 @@ class DataTables
/**
* DataTables using Query.
*
* @param \Illuminate\Database\Query\Builder|mixed $builder
* @return DataTableAbstract|QueryDataTable
* @param \Illuminate\Database\Query\Builder|mixed $builder
* @return QueryDataTable|DataTableAbstract
*/
public function query($builder)
{
@@ -107,8 +110,8 @@ class DataTables
/**
* DataTables using Eloquent Builder.
*
* @param \Illuminate\Database\Eloquent\Builder|mixed $builder
* @return DataTableAbstract|EloquentDataTable
* @param \Illuminate\Database\Eloquent\Builder|mixed $builder
* @return EloquentDataTable|DataTableAbstract
*/
public function eloquent($builder)
{
@@ -118,8 +121,8 @@ class DataTables
/**
* DataTables using Collection.
*
* @param \Illuminate\Support\Collection|array $collection
* @return DataTableAbstract|CollectionDataTable
* @param \Illuminate\Support\Collection|array $collection
* @return CollectionDataTable|DataTableAbstract
*/
public function collection($collection)
{
@@ -129,8 +132,8 @@ class DataTables
/**
* DataTables using Collection.
*
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection|array $collection
* @return DataTableAbstract|ApiResourceDataTable
* @param \Illuminate\Http\Resources\Json\AnonymousResourceCollection|array $collection
* @return ApiResourceDataTable|DataTableAbstract
*/
public function resource($resource)
{
@@ -141,6 +144,7 @@ class DataTables
* Get html builder instance.
*
* @return \Yajra\DataTables\Html\Builder
*
* @throws \Exception
*/
public function getHtmlBuilder()

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\Relation;
use Yajra\DataTables\Exceptions\Exception;
@@ -20,7 +21,7 @@ class EloquentDataTable extends QueryDataTable
/**
* Can the DataTable engine be created with these parameters.
*
* @param mixed $source
* @param mixed $source
* @return bool
*/
public static function canCreate($source)
@@ -31,7 +32,7 @@ class EloquentDataTable extends QueryDataTable
/**
* EloquentEngine constructor.
*
* @param mixed $model
* @param mixed $model
*/
public function __construct($model)
{
@@ -76,10 +77,10 @@ class EloquentDataTable extends QueryDataTable
/**
* Compile query builder where clause depending on configurations.
*
* @param mixed $query
* @param string $columnName
* @param string $keyword
* @param string $boolean
* @param mixed $query
* @param string $columnName
* @param string $keyword
* @param string $boolean
*/
protected function compileQuerySearch($query, $columnName, $keyword, $boolean = 'or')
{
@@ -91,15 +92,21 @@ class EloquentDataTable extends QueryDataTable
return parent::compileQuerySearch($query, $columnName, $keyword, $boolean);
}
$query->{$boolean . 'WhereHas'}($relation, function (Builder $query) use ($column, $keyword) {
parent::compileQuerySearch($query, $column, $keyword, '');
});
if ($this->isMorphRelation($relation)) {
$query->{$boolean . 'WhereHasMorph'}($relation, '*', function (Builder $query) use ($column, $keyword) {
parent::compileQuerySearch($query, $column, $keyword, '');
});
} else {
$query->{$boolean . 'WhereHas'}($relation, function (Builder $query) use ($column, $keyword) {
parent::compileQuerySearch($query, $column, $keyword, '');
});
}
}
/**
* Resolve the proper column name be used.
*
* @param string $column
* @param string $column
* @return string
*/
protected function resolveRelationColumn($column)
@@ -115,10 +122,29 @@ class EloquentDataTable extends QueryDataTable
return $this->joinEagerLoadedColumn($relation, $columnName);
}
/**
* Check if a relation is a morphed one or not.
*
* @param string $relation
* @return bool
*/
protected function isMorphRelation($relation)
{
$isMorph = false;
if ($relation !== null && $relation !== '') {
$relationParts = explode('.', $relation);
$firstRelation = array_shift($relationParts);
$model = $this->query->getModel();
$isMorph = method_exists($model, $firstRelation) && $model->$firstRelation() instanceof MorphTo;
}
return $isMorph;
}
/**
* Check if a relation was not used on eager loading.
*
* @param string $relation
* @param string $relation
* @return bool
*/
protected function isNotEagerLoaded($relation)
@@ -131,9 +157,10 @@ class EloquentDataTable extends QueryDataTable
/**
* Join eager loaded relation and get the related column name.
*
* @param string $relation
* @param string $relationColumn
* @param string $relation
* @param string $relationColumn
* @return string
*
* @throws \Yajra\DataTables\Exceptions\Exception
*/
protected function joinEagerLoadedColumn($relation, $relationColumn)
@@ -162,16 +189,18 @@ class EloquentDataTable extends QueryDataTable
case $model instanceof HasOneThrough:
$pivot = explode('.', $model->getQualifiedParentKeyName())[0]; // extract pivot table from key
$pivotPK = $pivot . '.' . $model->getLocalKeyName();
$pivotPK = $pivot . '.' . $model->getFirstKeyName();
$pivotFK = $model->getQualifiedLocalKeyName();
$this->performJoin($pivot, $pivotPK, $pivotFK);
$related = $model->getRelated();
$table = $related->getTable();
$tablePK = $related->getForeignKey();
$tablePK = $model->getSecondLocalKeyName();
$foreign = $pivot . '.' . $tablePK;
$other = $related->getQualifiedKeyName();
$lastQuery->addSelect($lastQuery->getModel()->getTable().'.*');
break;
case $model instanceof HasOneOrMany:
@@ -199,10 +228,10 @@ class EloquentDataTable extends QueryDataTable
/**
* Perform join query.
*
* @param string $table
* @param string $foreign
* @param string $other
* @param string $type
* @param string $table
* @param string $foreign
* @param string $other
* @param string $type
*/
protected function performJoin($table, $foreign, $other, $type = 'left')
{

View File

@@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Facade;
/**
* @mixin \Yajra\DataTables\DataTables
*
* @method static \Yajra\DataTables\EloquentDatatable eloquent($builder)
* @method static \Yajra\DataTables\QueryDataTable query($builder)
* @method static \Yajra\DataTables\CollectionDataTable collection($collection)

View File

@@ -2,7 +2,9 @@
namespace Yajra\DataTables\Processors;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Arr;
use Yajra\DataTables\Contracts\Formatter;
use Yajra\DataTables\Utilities\Helper;
class DataProcessor
@@ -67,10 +69,10 @@ class DataProcessor
protected $exceptions = ['DT_RowId', 'DT_RowClass', 'DT_RowData', 'DT_RowAttr'];
/**
* @param mixed $results
* @param array $columnDef
* @param array $templates
* @param int $start
* @param mixed $results
* @param array $columnDef
* @param array $templates
* @param int $start
*/
public function __construct($results, array $columnDef, array $templates, $start)
{
@@ -91,7 +93,7 @@ class DataProcessor
/**
* Process data to output on browser.
*
* @param bool $object
* @param bool $object
* @return array
*/
public function process($object = false)
@@ -120,15 +122,22 @@ class DataProcessor
/**
* Process add columns.
*
* @param mixed $data
* @param mixed $row
* @param mixed $data
* @param mixed $row
* @return array
*/
protected function addColumns($data, $row)
{
foreach ($this->appendColumns as $key => $value) {
$value['content'] = Helper::compileContent($value['content'], $data, $row);
$data = Helper::includeInArray($value, $data);
foreach ($this->appendColumns as $value) {
if ($value['content'] instanceof Formatter) {
$column = str_replace('_formatted', '', $value['name']);
$value['content'] = $value['content']->format($data[$column], $row);
} else {
$value['content'] = Helper::compileContent($value['content'], $data, $row);
}
$data = Helper::includeInArray($value, $data);
}
return $data;
@@ -137,8 +146,8 @@ class DataProcessor
/**
* Process edit columns.
*
* @param mixed $data
* @param mixed $row
* @param mixed $data
* @param mixed $row
* @return array
*/
protected function editColumns($data, $row)
@@ -154,8 +163,8 @@ class DataProcessor
/**
* Setup additional DT row variables.
*
* @param mixed $data
* @param mixed $row
* @param mixed $data
* @param mixed $row
* @return array
*/
protected function setupRowVariables($data, $row)
@@ -173,32 +182,31 @@ class DataProcessor
/**
* Get only needed columns.
*
* @param array $data
* @param array $data
* @return array
*/
protected function selectOnlyNeededColumns(array $data)
{
if (is_null($this->onlyColumns)) {
return $data;
} else {
$results = [];
foreach ($this->onlyColumns as $onlyColumn) {
Arr::set($results, $onlyColumn, Arr::get($data, $onlyColumn));
}
foreach ($this->exceptions as $exception) {
if ($column = Arr::get($data, $exception)) {
Arr::set($results, $exception, $column);
}
}
return $results;
}
$results = [];
foreach ($this->onlyColumns as $onlyColumn) {
Arr::set($results, $onlyColumn, Arr::get($data, $onlyColumn));
}
foreach ($this->exceptions as $exception) {
if ($column = Arr::get($data, $exception)) {
Arr::set($results, $exception, $column);
}
}
return $results;
}
/**
* Remove declared hidden columns.
*
* @param array $data
* @param array $data
* @return array
*/
protected function removeExcessColumns(array $data)
@@ -213,7 +221,7 @@ class DataProcessor
/**
* Flatten array with exceptions.
*
* @param array $array
* @param array $array
* @return array
*/
public function flatten(array $array)
@@ -233,7 +241,7 @@ class DataProcessor
/**
* Escape column values as declared.
*
* @param array $output
* @param array $output
* @return array
*/
protected function escapeColumns(array $output)
@@ -253,9 +261,9 @@ class DataProcessor
}
/**
* Escape all values of row.
* Escape all string or Htmlable values of row.
*
* @param array $row
* @param array $row
* @return array
*/
protected function escapeRow(array $row)
@@ -263,7 +271,7 @@ class DataProcessor
$arrayDot = array_filter(Arr::dot($row));
foreach ($arrayDot as $key => $value) {
if (! in_array($key, $this->rawColumns)) {
$arrayDot[$key] = e($value);
$arrayDot[$key] = (is_string($value) || $value instanceof Htmlable) ? e($value) : $value;
}
}

View File

@@ -18,8 +18,8 @@ class RowProcessor
private $row;
/**
* @param mixed $data
* @param mixed $row
* @param mixed $data
* @param mixed $row
*/
public function __construct($data, $row)
{
@@ -30,8 +30,8 @@ class RowProcessor
/**
* Process DT RowId and Class value.
*
* @param string $attribute
* @param string|callable $template
* @param string $attribute
* @param string|callable $template
* @return $this
*/
public function rowValue($attribute, $template)
@@ -50,8 +50,8 @@ class RowProcessor
/**
* Process DT Row Data and Attr.
*
* @param string $attribute
* @param array $template
* @param string $attribute
* @param array $template
* @return $this
*/
public function rowData($attribute, array $template)

View File

@@ -2,11 +2,11 @@
namespace Yajra\DataTables;
use Illuminate\Support\Str;
use Illuminate\Database\Query\Builder;
use Yajra\DataTables\Utilities\Helper;
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Str;
use Yajra\DataTables\Utilities\Helper;
class QueryDataTable extends DataTableAbstract
{
@@ -62,7 +62,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Can the DataTable engine be created with these parameters.
*
* @param mixed $source
* @param mixed $source
* @return bool
*/
public static function canCreate($source)
@@ -71,7 +71,7 @@ class QueryDataTable extends DataTableAbstract
}
/**
* @param \Illuminate\Database\Query\Builder $builder
* @param \Illuminate\Database\Query\Builder $builder
*/
public function __construct(Builder $builder)
{
@@ -88,8 +88,9 @@ class QueryDataTable extends DataTableAbstract
/**
* Organizes works.
*
* @param bool $mDataSupport
* @param bool $mDataSupport
* @return \Illuminate\Http\JsonResponse
*
* @throws \Exception
*/
public function make($mDataSupport = true)
@@ -107,6 +108,28 @@ class QueryDataTable extends DataTableAbstract
}
}
/**
* Perform search using search pane values.
*/
protected function searchPanesSearch()
{
$columns = $this->request->get('searchPanes', []);
foreach ($columns as $column => $values) {
if ($this->isBlacklisted($column)) {
continue;
}
if ($this->searchPanes[$column] && $callback = $this->searchPanes[$column]['builder']) {
$callback($this->query, $values);
} else {
$this->query->whereIn($column, $values);
}
$this->isFilterApplied = true;
}
}
/**
* Prepare query by executing count, filter, order and paginate.
*/
@@ -117,9 +140,10 @@ class QueryDataTable extends DataTableAbstract
if ($this->totalRecords) {
$this->filterRecords();
$this->ordering();
$this->paginate();
}
$this->ordering();
$this->paginate();
}
$this->prepared = true;
@@ -188,12 +212,7 @@ class QueryDataTable extends DataTableAbstract
*/
public function count()
{
$builder = $this->prepareCountQuery();
$table = $this->connection->raw('(' . $builder->toSql() . ') count_row_table');
return $this->connection->table($table)
->setBindings($builder->getBindings())
->count();
return $this->prepareCountQuery()->count();
}
/**
@@ -201,16 +220,21 @@ class QueryDataTable extends DataTableAbstract
*
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
*/
protected function prepareCountQuery()
public function prepareCountQuery()
{
$builder = clone $this->query;
if (! $this->isComplexQuery($builder)) {
$row_count = $this->wrap('row_count');
$builder->select($this->connection->raw("'1' as {$row_count}"));
if (! $this->keepSelectBindings) {
$builder->setBindings([], 'select');
}
if ($this->isComplexQuery($builder)) {
$table = $this->connection->raw('('.$builder->toSql().') count_row_table');
return $this->connection->table($table)
->setBindings($builder->getBindings());
}
$row_count = $this->wrap('row_count');
$builder->select($this->connection->raw("'1' as {$row_count}"));
if (! $this->keepSelectBindings) {
$builder->setBindings([], 'select');
}
return $builder;
@@ -219,7 +243,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Check if builder query uses complex sql.
*
* @param \Illuminate\Database\Query\Builder $builder
* @param \Illuminate\Database\Query\Builder $builder
* @return bool
*/
protected function isComplexQuery($builder)
@@ -230,7 +254,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Wrap column with DB grammar.
*
* @param string $column
* @param string $column
* @return string
*/
protected function wrap($column)
@@ -287,7 +311,7 @@ class QueryDataTable extends DataTableAbstract
}
if ($this->hasFilterColumn($column)) {
$keyword = $this->getColumnSearchKeyword($index, $raw = true);
$keyword = $this->getColumnSearchKeyword($index, true);
$this->applyFilterColumn($this->getBaseQueryBuilder(), $column, $keyword);
} else {
$column = $this->resolveRelationColumn($column);
@@ -302,7 +326,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Check if column has custom filter handler.
*
* @param string $columnName
* @param string $columnName
* @return bool
*/
public function hasFilterColumn($columnName)
@@ -313,8 +337,8 @@ class QueryDataTable extends DataTableAbstract
/**
* Get column keyword to use for search.
*
* @param int $i
* @param bool $raw
* @param int $i
* @param bool $raw
* @return string
*/
protected function getColumnSearchKeyword($i, $raw = false)
@@ -330,10 +354,10 @@ class QueryDataTable extends DataTableAbstract
/**
* Apply filterColumn api search.
*
* @param mixed $query
* @param string $columnName
* @param string $keyword
* @param string $boolean
* @param mixed $query
* @param string $columnName
* @param string $keyword
* @param string $boolean
*/
protected function applyFilterColumn($query, $columnName, $keyword, $boolean = 'and')
{
@@ -354,7 +378,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Get the base query builder instance.
*
* @param mixed $instance
* @param mixed $instance
* @return \Illuminate\Database\Query\Builder
*/
protected function getBaseQueryBuilder($instance = null)
@@ -373,7 +397,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Resolve the proper column name be used.
*
* @param string $column
* @param string $column
* @return string
*/
protected function resolveRelationColumn($column)
@@ -384,14 +408,13 @@ class QueryDataTable extends DataTableAbstract
/**
* Compile queries for column search.
*
* @param int $i
* @param string $column
* @param string $keyword
* @param int $i
* @param string $column
* @param string $keyword
*/
protected function compileColumnSearch($i, $column, $keyword)
{
if ($this->request->isRegex($i)) {
$column = strstr($column, '(') ? $this->connection->raw($column) : $column;
$this->regexColumnSearch($column, $keyword);
} else {
$this->compileQuerySearch($this->query, $column, $keyword, '');
@@ -401,11 +424,13 @@ class QueryDataTable extends DataTableAbstract
/**
* Compile regex query column search.
*
* @param mixed $column
* @param string $keyword
* @param mixed $column
* @param string $keyword
*/
protected function regexColumnSearch($column, $keyword)
{
$column = $this->wrap($column);
switch ($this->connection->getDriverName()) {
case 'oracle':
$sql = ! $this->config->isCaseInsensitive()
@@ -431,7 +456,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Wrap a column and cast based on database driver.
*
* @param string $column
* @param string $column
* @return string
*/
protected function castColumn($column)
@@ -449,10 +474,10 @@ class QueryDataTable extends DataTableAbstract
/**
* Compile query builder where clause depending on configurations.
*
* @param mixed $query
* @param string $column
* @param string $keyword
* @param string $boolean
* @param mixed $query
* @param string $column
* @param string $keyword
* @param string $boolean
*/
protected function compileQuerySearch($query, $column, $keyword, $boolean = 'or')
{
@@ -471,8 +496,8 @@ class QueryDataTable extends DataTableAbstract
* Patch for fix about ambiguous field.
* Ambiguous field error will appear when query use join table and search with keyword.
*
* @param mixed $query
* @param string $column
* @param mixed $query
* @param string $column
* @return string
*/
protected function addTablePrefix($query, $column)
@@ -490,7 +515,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Prepare search keyword based on configurations.
*
* @param string $keyword
* @param string $keyword
* @return string
*/
protected function prepareKeyword($keyword)
@@ -517,8 +542,8 @@ class QueryDataTable extends DataTableAbstract
/**
* Add custom filter handler for the give column.
*
* @param string $column
* @param callable $callback
* @param string $column
* @param callable $callback
* @return $this
*/
public function filterColumn($column, callable $callback)
@@ -531,9 +556,9 @@ class QueryDataTable extends DataTableAbstract
/**
* Order each given columns versus the given custom sql.
*
* @param array $columns
* @param string $sql
* @param array $bindings
* @param array $columns
* @param string $sql
* @param array $bindings
* @return $this
*/
public function orderColumns(array $columns, $sql, $bindings = [])
@@ -548,10 +573,11 @@ class QueryDataTable extends DataTableAbstract
/**
* Override default column ordering.
*
* @param string $column
* @param string $sql
* @param array $bindings
* @param string $column
* @param string|\Closure $sql
* @param array $bindings
* @return $this
*
* @internal string $1 Special variable that returns the requested order direction of the column.
*/
public function orderColumn($column, $sql, $bindings = [])
@@ -577,7 +603,7 @@ class QueryDataTable extends DataTableAbstract
* Paginate dataTable using limit without offset
* with additional where clause via callback.
*
* @param callable $callback
* @param callable $callback
* @return $this
*/
public function limit(callable $callback)
@@ -606,9 +632,9 @@ class QueryDataTable extends DataTableAbstract
/**
* Add column in collection.
*
* @param string $name
* @param string|callable $content
* @param bool|int $order
* @param string $name
* @param string|callable $content
* @param bool|int $order
* @return $this
*/
public function addColumn($name, $content, $order = false)
@@ -635,7 +661,7 @@ class QueryDataTable extends DataTableAbstract
{
collect($this->request->orderableColumns())
->map(function ($orderable) {
$orderable['name'] = $this->getColumnName($orderable['column'], true);
$orderable['name'] = $this->getColumnName($orderable['column'], null, true);
return $orderable;
})
@@ -649,8 +675,8 @@ class QueryDataTable extends DataTableAbstract
$this->applyOrderColumn($column, $orderable);
} else {
$nullsLastSql = $this->getNullsLastSql($column, $orderable['direction']);
$normalSql = $this->wrap($column) . ' ' . $orderable['direction'];
$sql = $this->nullsLast ? $nullsLastSql : $normalSql;
$normalSql = $this->wrap($column) . ' ' . $orderable['direction'];
$sql = $this->nullsLast ? $nullsLastSql : $normalSql;
$this->query->orderByRaw($sql);
}
});
@@ -659,7 +685,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Check if column has custom sort handler.
*
* @param string $column
* @param string $column
* @return bool
*/
protected function hasOrderColumn($column)
@@ -670,12 +696,16 @@ class QueryDataTable extends DataTableAbstract
/**
* Apply orderColumn custom query.
*
* @param string $column
* @param array $orderable
* @param string $column
* @param array $orderable
*/
protected function applyOrderColumn($column, $orderable)
{
$sql = $this->columnDef['order'][$column]['sql'];
if ($sql === false) {
return;
}
if (is_callable($sql)) {
call_user_func($sql, $this->query, $orderable['direction']);
} else {
@@ -688,8 +718,8 @@ class QueryDataTable extends DataTableAbstract
/**
* Get NULLS LAST SQL.
*
* @param string $column
* @param string $direction
* @param string $column
* @param string $direction
* @return string
*/
protected function getNullsLastSql($column, $direction)
@@ -706,7 +736,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Perform global search for the given keyword.
*
* @param string $keyword
* @param string $keyword
*/
protected function globalSearch($keyword)
{
@@ -733,14 +763,16 @@ class QueryDataTable extends DataTableAbstract
/**
* Append debug parameters on output.
*
* @param array $output
* @param array $output
* @return array
*/
protected function showDebugger(array $output)
{
$query_log = $this->connection->getQueryLog();
array_walk_recursive($query_log, function (&$item, $key) {
$item = utf8_encode($item);
array_walk_recursive($query_log, function (&$item) {
if (is_string($item)) {
$item = utf8_encode($item);
}
});
$output['queries'] = $query_log;
@@ -752,7 +784,7 @@ class QueryDataTable extends DataTableAbstract
/**
* Attach custom with meta on response.
*
* @param array $data
* @param array $data
* @return array
*/
protected function attachAppends(array $data)

View File

@@ -14,7 +14,7 @@ class Config
/**
* Config constructor.
*
* @param \Illuminate\Contracts\Config\Repository $repository
* @param \Illuminate\Contracts\Config\Repository $repository
*/
public function __construct(Repository $repository)
{
@@ -64,8 +64,8 @@ class Config
/**
* Get the specified configuration value.
*
* @param string $key
* @param mixed $default
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
@@ -76,8 +76,8 @@ class Config
/**
* Set a given configuration value.
*
* @param array|string $key
* @param mixed $value
* @param array|string $key
* @param mixed $value
* @return void
*/
public function set($key, $value = null)

View File

@@ -3,17 +3,17 @@
namespace Yajra\DataTables\Utilities;
use DateTime;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Contracts\Support\Arrayable;
class Helper
{
/**
* Places item of extra columns into results by care of their order.
*
* @param array $item
* @param array $array
* @param array $item
* @param array $array
* @return array
*/
public static function includeInArray($item, $array)
@@ -40,8 +40,8 @@ class Helper
/**
* Check if item order is valid.
*
* @param array $item
* @param array $array
* @param array $item
* @param array $array
* @return bool
*/
protected static function isItemOrderInvalid($item, $array)
@@ -52,16 +52,25 @@ class Helper
/**
* Determines if content is callable or blade string, processes and returns.
*
* @param mixed $content Pre-processed content
* @param array $data data to use with blade template
* @param mixed $param parameter to call with callable
* @param mixed $content Pre-processed content
* @param array $data data to use with blade template
* @param mixed $param parameter to call with callable
* @return mixed
*/
public static function compileContent($content, array $data, $param)
{
if (is_string($content)) {
return static::compileBlade($content, static::getMixedValue($data, $param));
} elseif (is_callable($content)) {
}
if (is_callable($content)) {
$reflection = new \ReflectionFunction($content);
$arguments = $reflection->getParameters();
if (count($arguments) > 0) {
return app()->call($content, [$arguments[0]->name => $param]);
}
return $content($param);
}
@@ -71,9 +80,10 @@ class Helper
/**
* Parses and compiles strings by using Blade Template System.
*
* @param string $str
* @param array $data
* @param string $str
* @param array $data
* @return mixed
*
* @throws \Exception
*/
public static function compileBlade($str, $data = [])
@@ -93,8 +103,8 @@ class Helper
/**
* Get a mixed value of custom data and the parameters.
*
* @param array $data
* @param mixed $param
* @param array $data
* @param mixed $param
* @return array
*/
public static function getMixedValue(array $data, $param)
@@ -115,7 +125,7 @@ class Helper
/**
* Cast the parameter into an array.
*
* @param mixed $param
* @param mixed $param
* @return array
*/
public static function castToArray($param)
@@ -136,7 +146,7 @@ class Helper
/**
* Get equivalent or method of query builder.
*
* @param string $method
* @param string $method
* @return string
*/
public static function getOrMethod($method)
@@ -151,14 +161,14 @@ class Helper
/**
* Converts array object values to associative array.
*
* @param mixed $row
* @param array $filters
* @param mixed $row
* @param array $filters
* @return array
*/
public static function convertToArray($row, $filters = [])
{
$row = method_exists($row, 'makeHidden') ? $row->makeHidden(Arr::get($filters, 'hidden', [])) : $row;
$row = method_exists($row, 'makeVisible') ? $row->makeVisible(Arr::get($filters, 'visible', [])) : $row;
$row = is_object($row) && method_exists($row, 'makeHidden') ? $row->makeHidden(Arr::get($filters, 'hidden', [])) : $row;
$row = is_object($row) && method_exists($row, 'makeVisible') ? $row->makeVisible(Arr::get($filters, 'visible', [])) : $row;
$data = $row instanceof Arrayable ? $row->toArray() : (array) $row;
foreach ($data as &$value) {
@@ -173,7 +183,7 @@ class Helper
}
/**
* @param array $data
* @param array $data
* @return array
*/
public static function transform(array $data)
@@ -186,7 +196,7 @@ class Helper
/**
* Transform row data into an array.
*
* @param mixed $row
* @param mixed $row
* @return array
*/
protected static function transformRow($row)
@@ -209,7 +219,7 @@ class Helper
/**
* Build parameters depending on # of arguments passed.
*
* @param array $args
* @param array $args
* @return array
*/
public static function buildParameters(array $args)
@@ -233,9 +243,9 @@ class Helper
/**
* Replace all pattern occurrences with keyword.
*
* @param array $subject
* @param string $keyword
* @param string $pattern
* @param array $subject
* @param string $keyword
* @param string $pattern
* @return array
*/
public static function replacePatternWithKeyword(array $subject, $keyword, $pattern = '$1')
@@ -255,8 +265,8 @@ class Helper
/**
* Get column name from string.
*
* @param string $str
* @param bool $wantsAlias
* @param string $str
* @param bool $wantsAlias
* @return string
*/
public static function extractColumnName($str, $wantsAlias)
@@ -281,8 +291,8 @@ class Helper
/**
* Adds % wildcards to the given string.
*
* @param string $str
* @param bool $lowercase
* @param string $str
* @param bool $lowercase
* @return string
*/
public static function wildcardLikeString($str, $lowercase = true)
@@ -293,9 +303,9 @@ class Helper
/**
* Adds wildcards to the given string.
*
* @param string $str
* @param string $wildcard
* @param bool $lowercase
* @param string $str
* @param string $wildcard
* @param bool $lowercase
* @return string
*/
public static function wildcardString($str, $wildcard, $lowercase = true)

View File

@@ -3,14 +3,7 @@
namespace Yajra\DataTables\Utilities;
/**
* @method mixed input($key, $default = null)
* @method mixed get($key, $default = null)
* @method mixed query($key, $default = null)
* @method mixed has($key)
* @method mixed merge(array $values)
* @method bool wantsJson()
* @method bool ajax()
* @method array all()
* @mixin \Illuminate\Http\Request
*/
class Request
{
@@ -30,8 +23,8 @@ class Request
/**
* Proxy non existing method calls to request class.
*
* @param mixed $name
* @param mixed $arguments
* @param mixed $name
* @param mixed $arguments
* @return mixed
*/
public function __call($name, $arguments)
@@ -44,7 +37,7 @@ class Request
/**
* Get attributes from request instance.
*
* @param string $name
* @param string $name
* @return mixed
*/
public function __get($name)
@@ -75,7 +68,7 @@ class Request
/**
* Check if DataTables must uses regular expressions.
*
* @param int $index
* @param int $index
* @return bool
*/
public function isRegex($index)
@@ -119,7 +112,7 @@ class Request
/**
* Check if a column is orderable.
*
* @param int $index
* @param int $index
* @return bool
*/
public function isColumnOrderable($index)
@@ -147,8 +140,8 @@ class Request
/**
* Check if a column is searchable.
*
* @param int $i
* @param bool $column_search
* @param int $i
* @param bool $column_search
* @return bool
*/
public function isColumnSearchable($i, $column_search = true)
@@ -172,12 +165,12 @@ class Request
/**
* Get column's search value.
*
* @param int $index
* @param int $index
* @return string
*/
public function columnKeyword($index)
{
$keyword = $this->request->input("columns.$index.search.value");
$keyword = $this->request->input("columns.$index.search.value") ?? '';
return $this->prepareKeyword($keyword);
}
@@ -185,7 +178,7 @@ class Request
/**
* Prepare keyword string value.
*
* @param string|array $keyword
* @param string|array $keyword
* @return string
*/
protected function prepareKeyword($keyword)
@@ -204,7 +197,7 @@ class Request
*/
public function keyword()
{
$keyword = $this->request->input('search.value');
$keyword = $this->request->input('search.value') ?? '';
return $this->prepareKeyword($keyword);
}
@@ -212,13 +205,30 @@ class Request
/**
* Get column identity from input or database.
*
* @param int $i
* @param int $i
* @param string|null $type
* @return string
*/
public function columnName($i)
public function columnName($i, $type = null)
{
$column = $this->request->input("columns.$i");
if (isset($type) && isset($column['data']) && is_array($column['data'])) {
if (isset($column['data'][$type]) && $column['data'][$type] != '') {
return $column['data'][$type];
}
if (isset($column['data']['display']) && $column['data']['display'] != '') {
return $column['data']['display'];
}
if (isset($column['data']['_']) && $column['data']['_'] != '') {
return $column['data']['_'];
}
return $column['name'];
}
return isset($column['name']) && $column['name'] != '' ? $column['name'] : $column['data'];
}

View File

@@ -100,7 +100,7 @@ return [
'raw' => ['action'],
/*
* List of columns are are forbidden from being searched/sorted.
* List of columns are forbidden from being searched/sorted.
*/
'blacklist' => ['password', 'remember_token'],

View File

@@ -5,7 +5,7 @@ if (! function_exists('datatables')) {
* Helper to make a new DataTable instance from source.
* Or return the factory if source is not set.
*
* @param mixed $source
* @param mixed $source
* @return \Yajra\DataTables\DataTableAbstract|\Yajra\DataTables\DataTables
*/
function datatables($source = null)

View File

@@ -4,7 +4,7 @@ if (! function_exists('config_path')) {
/**
* Get the configuration path.
*
* @param string $path
* @param string $path
* @return string
*/
function config_path($path = '')
@@ -17,7 +17,7 @@ if (! function_exists('public_path')) {
/**
* Return the path to public dir.
*
* @param null $path
* @param null $path
* @return string
*/
function public_path($path = null)