php Laravel中的Yajra数据表问题

8yparm6h  于 2023-05-21  发布在  PHP
关注(0)|答案(6)|浏览(166)

我试图在我的laravel项目中实现一个数据表,我在项目中安装了yajra数据表和所有东西。
我将这些添加到app.php:

Yajra\DataTables\DataTablesServiceProvider::class,
'DataTables' => Yajra\DataTables\Facades\DataTables::class,

但当我尝试使用命令创建新的数据表时

php artisan datatables:make Companies

我得到这个错误:* DataTables命名空间中没有定义命令 *。
任何想法如何解决这个问题!!

xxhby3vn

xxhby3vn1#

如果 * 错误 *:

composer require yajra/laravel-datatables-buttons

您可以尝试:

composer require yajra/laravel-datatables-buttons:*

它可以在yajra/laravel/datatables-oracle:9.0上工作

swvgeqrz

swvgeqrz2#

只要做三件事
1.运行这个命令“composer require yajra/laravel-datatables-buttons”
1.在config/app.php文件中的providers中粘贴这两行:Yajra\DataTables\DataTablesServiceProvider::class,Yajra\DataTables\ButtonsServiceProvider::class,
1.运行此“php artisan vendor:publish --tag=datatables-buttons”

wgxvkvu9

wgxvkvu93#

解决方案1在您的项目中查找此文件

vendor/datatables/buttons.server-side.js

复制它并将其放到assets公用文件夹中,然后确保在

{{ $dataTable->scripts() }}

所以应该是这样

<script src="{{ url('/') }}/assets/js/buttons.server-side.js"></script>
{{ $dataTable->scripts() }}

希望能修好

解决方案2移除按钮。在DataTable类中的构建方法上,通过添加如下内容来移除按钮

->parameters([
        'dom' => 'Bfrtip',
        'buttons' => [],
    ]);

最后的结果应该是这样的

public function html()
{
    return $this->builder()
                ->setTableId('users-table')
                ->columns($this->getColumns())
                ->minifiedAjax()
                ->dom('Bfrtip')
                ->orderBy(1)
                -->parameters([
                    'dom' => 'Bfrtip',
                    'buttons' => [],
                ]);
}

结论如果还是错误,去检查一下有没有警告。

ldxq2e6h

ldxq2e6h4#

如果你已经将Laravel版本升级到Laravel 9
您将需要Yajra DataTables版本:^10

composer require yajra/laravel-datatables-oracle:"^10.0"

修改app.php

Service Provider & Facade 
Register provider and facade on your config/app.php file.

'providers' => [
    ...,
    Yajra\DataTables\DataTablesServiceProvider::class,
]

'aliases' => [
    ...,
    'DataTables' => Yajra\DataTables\Facades\DataTables::class,
]

然后发表

php artisan vendor:publish --provider="Yajra\DataTables\DataTablesServiceProvider"

发布DataTableServiceProvider后
安装数据表按钮9.0

composer require yajra/laravel-datatables-buttons:9.0

那就跑啊

php artisan datatables:make Companies

作者:Yajra / ArJay Angeles
https://github.com/yajra/laravel-datatables

vulvrdjw

vulvrdjw5#

试试这个

composer require yajra/laravel-datatables-oracle

在***config-> app.php***中添加提供程序和别名

'providers' => [
        ...
        Yajra\DataTables\DataTablesServiceProvider::class,
    ]
    'aliases' => [
        ...
        'DataTables' => Yajra\DataTables\Facades\DataTables::class,
    ]

并运行命令

php artisan vendor:publish --provider="Yajra\DataTables\DataTablesServiceProvider"

composer require phpoffice/phpspreadsheet

composer update

composer require maatwebsite/excel

composer require yajra/laravel-datatables-buttons

然后可以创建数据表

php artisan datatables:make Companies
xbp102n0

xbp102n06#

要解决这个问题,需要安装yajra/laravel-datatables-buttons
因此运行以下命令:composer require yajra/laravel-datatables-buttons
参考:https://github.com/yajra/laravel-datatables/issues/1392

相关问题