laravel-datatables
laravel-datatables copied to clipboard
PHP 8.1 ctype_lower() deprecation notice when no title is supplied
Summary of problem or feature request
This deprecation warning appears a lot in datatables with laravel 9 and PHP 8.1:
ctype_lower(): Argument of type int will be interpreted as string in the future in /vendor/laravel/framework/src/Illuminate/Support/Str.php on line 903
Code snippet of problem
This warning is generated for each column without a title, for example like this:
$transactionsDataTable = $builder->columns([
[
'data' => 'source_sort_code',
'name' => 'source_sort_code',
'visible' => false,
'orderable' => false,
],
The workaround is to add a dummy title:
[
'data' => 'source_sort_code',
'name' => 'source_sort_code',
'visible' => false,
'orderable' => false,
'title' => '',
],
This example is a searchable, but not displayed column. (The data is actually displayed formatted along with other data in another column, so the user does see it, and it makes sense being able to search it even if this specfic column is not visible.)
Here is a partial stack dump showing the route to the Laravel function. The problem stems from getQualifiedTitle()
calling Str::snake()
on a title which defaults to an incrementing integer (12 in this case) when a title is not explicitely defined in the DataTable declaration.
[2022-06-07 11:04:42] dev.DEBUG: Not a string {"value":12} {"memory_usage":"4 MB","process_id":25,"uid":"33bef6e0f662e568","application":"Bluejay","local_user_id":1}
[2022-06-07 11:04:42] dev.DEBUG: Exception: stop in /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Str.php:903
Stack trace:
#0 /var/www/html/vendor/yajra/laravel-datatables-html/src/Html/Options/HasColumns.php(123): Illuminate\Support\Str::snake()
#1 /var/www/html/vendor/yajra/laravel-datatables-html/src/Html/Options/HasColumns.php(109): Yajra\DataTables\Html\Builder->getQualifiedTitle()
#2 /var/www/html/vendor/yajra/laravel-datatables-html/src/Html/Options/HasColumns.php(80): Yajra\DataTables\Html\Builder->setTitle()
#3 /var/www/html/packages-dev/bluejay-core/src/Http/Controllers/TransactionController.php(23): Yajra\DataTables\Html\Builder->columns()
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): ...\Controllers\TransactionController->index()
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\Routing\ControllerDispatcher->dispatch()
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(204): Illuminate\Routing\Route->runController()
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(725): Illuminate\Routing\Route->run()
System details
- Operating System
- PHP Version 8.1
- Laravel Version 9.14
- Laravel-Datatables Version 12
I would suggest, if the colulmn is not visible, then don't even attempt to look at the title.
Thanks for reporting, will check and fix when I got the chance. Please do not hesitate to submit a PR if you can.
I would suggest, if the column is not visible, then don't even attempt to look at the title.
I think we still need the title in cases where we used the colvis button.
Also, I would like suggest you use the Column builder instead.
[
'data' => 'source_sort_code',
'name' => 'source_sort_code',
'visible' => false,
'orderable' => false,
'title' => '',
],
Is equivalent to:
Column::make('source_sort_code')->visible(false)->orderable(false)
Thanks, I'll try the column builder. This is a really old project that started on Laravel 5.x and has upgraded all the way to 9, with DataTables, so there is a lot of legacy in that that is ripe for bringing up to current best practices.
If I get a chance to do a PR, I will.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 7 days since being marked as stale.