laravel-datatables: Declaration of Column::data does not compatible with Fluent::data
Summary of problem or feature request
Error
Declaration of Yajra\DataTables\Html\Column::data(array|string $value): static must be compatible with Illuminate\Support\Fluent::data($key = null, $default = null)
Code snippet of problem
File vendor/yajra/laravel-datatables-html/src/Html/Column.php, function data (line 305 - 310) was the reason:
public function data(array|string $value): static
{
$this->attributes['data'] = $value;
return $this;
}
System details
- Operating System: Mac OS 15
- PHP Version: 8.3
- Laravel Version: laravel/framework ^11.34
- Laravel-Datatables Version: yajra/laravel-datatables ^11.0
Solution
File vendor/yajra/laravel-datatables-html/src/Html/Column.php, change function data (line 305 - 310) to:
public function data($key = null, $default = null): static
{
$this->attributes['data'] = $key;
return $this;
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 20 (7 by maintainers)
I have the same problem, this was caused by the update in Laravel 11.34
For now you can downgrade using
composer update --with "laravel/framework:11.33.1".Should we petition to revert the latest PR (https://github.com/laravel/framework/pull/53665), remove the data method added to the framework, or move on with the quick solution suggested by @OzanKurt?
A good solution for this is to extend a decorator class instead of extending Fluent directly:
@yajra why dont you copy laravels fluent class into your codebase and you are good?
Here is the update that broke many projects:
https://github.com/laravel/framework/pull/53665
That is actually a great idea, having fluent as a standalone package. Simply something like
xxx/fluentwhich would not nuke anybodies codebase. 😄Dear friends, while waiting for the author to fix it, there is no better way than temporarily implementing the solution I mentioned at the end. Measures to close the code line or remove $default or change statics properties will cause other errors.
The solution is avoiding the error but having a second parameter here doesn’t make sense, we need to find a proper way to implement this method.