php - Laravel Yajra Datatables 自定义按钮操作

标签 php laravel datatable datatables

我正在使用 yajra/laravel-datatables-buttons我找不到足够有用的文档来帮助我。

我正在使用包中的创建按钮,如下所示:

enter image description here

它应该将我重定向到我的路线:http://laravel.blog/admin/posts/create

但它不断将我重定向到 http://laravel.blog/admin/posts/creer

它将“创造”翻译成“创造”,我不知道它为什么会这样做。我只用英语构建应用程序,从未使用法语作为路线或任何东西。

AdminPostsDatatable.php:

/**
     * Optional method if you want to use html builder.
     *
     * @return \Yajra\DataTables\Html\Builder
     */
    public function html()
    {
        return $this->builder()
                    ->setTableId('adminpostsdatatable-table')
                    ->columns($this->getColumns())
                    ->minifiedAjax()
                    ->dom('Bfrtip')
                    ->orderBy(1, 'desc')
                    ->buttons(
                        Button::make('create'),
                        Button::make('export'),
                        Button::make('print'),
                        Button::make('reset'),
                        Button::make('reload')
                    );
    }

admin.posts.index View :

@extends("layouts.app")

@section('content')

    <h1>Posts</h1>
    @if (session('status'))
        <div class="alert alert-success">
            {{ session('status') }}
        </div>
    @endif
    {!! $dataTable->table() !!}
@endsection

@push('scripts')
    {!! $dataTable->scripts() !!}
@endpush

路线:

|        | GET|HEAD  | admin                         | admin.                | Closure                                                                | web,auth                                             |
|        | POST      | admin/posts                   | admin.posts.store     | App\Http\Controllers\AdminPostsController@store                        | web,auth                                             |
|        | GET|HEAD  | admin/posts                   | admin.posts.index     | App\Http\Controllers\AdminPostsController@index                        | web,auth                                             |
|        | GET|HEAD  | admin/posts/create            | admin.posts.create    | App\Http\Controllers\AdminPostsController@create                       | web,auth                                             |
|        | PUT|PATCH | admin/posts/{post}            | admin.posts.update    | App\Http\Controllers\AdminPostsController@update                       | web,auth                                             |
|        | DELETE    | admin/posts/{post}            | admin.posts.destroy   | App\Http\Controllers\AdminPostsController@destroy                      | web,auth                                             |
|        | GET|HEAD  | admin/posts/{post}/edit       | admin.posts.edit      | App\Http\Controllers\AdminPostsController@edit                         | web,auth           

提前致谢。

最佳答案

我真的不知道这样做是否正确,但我想出了这个解决方案:

Button::make('create')->action("window.location = '".route('admin.posts.create')."';"),

关于php - Laravel Yajra Datatables 自定义按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59662957/

相关文章:

php - Zend Framework headMeta() - 关键字不附加

php - 页面加载后调用数据时 jquery 函数不起作用

php - 在 Laravel 中模拟具有关系的模型

php - 未找到基表或 View : 1146 Table 'Vojodb.users' doesn't exist

javascript - 如何禁用对数据表第一列的排序效果

LINQ 动态表达式 API,与 DBNull.Value 比较的谓词

javascript - 根据外部下拉列表过滤数据表行

向客户端报告进度的 PHP 脚本

Laravel - 设置测试数据库

php - 在 php 中使用时,MySQL 查询返回空结果