我在让 yajra laravel 数据表编辑器教程工作时遇到问题

我是 Laravel 和 Datatables/Editor 的新手。我在另一个 PHP 项目中使用了 DataTables 编辑器,但无法通过Yajra 插件让它在 Laravel 中工作。我按照本教程https://yajrabox.com/docs/laravel-datatables/master/editor-tutorial进行操作。一切都编译得很好,但结果并没有像我预期的那样工作。“编辑”和“删除”按钮显示为灰色且行不可选择。我怀疑我要么不包括 DataTables/Editor 脚本,要么解压缩 Editor.zip(不在教程中)。

我在屏幕上看到的图像

我正在使用: - PHP 版本:7.4.2 - Laravel 版本:6.17.1 - Laravel-DataTables Editor PHP 1.9.2(付费版本-zip 文件重命名为 Editor.zip 并包含在根文件夹中)

网页.php

   <?php


use App\DataTables\UsersDataTablesEditor;


Route::get('/', function () {

    return view('welcome');

});


Auth::routes();


Route::get('/home', 'HomeController@index')->name('home');

Route::get('/users', 'UsersController@index')->name('users.index');


// from https://yajrabox.com/docs/laravel-datatables/master/editor-tutorial

Route::post('/users', 'UsersController@store')->name('users.store');


// from https://yajrabox.com/docs/laravel-datatables/master/editor-usage

Route::post('editor', function(UsersDataTablesEditor $editor) {

    return $editor->process(request());

});

用户数据表编辑器.php


<?php


namespace App\DataTables;


use App\User;

use Illuminate\Database\Eloquent\Model;

use Illuminate\Validation\Rule;

use Yajra\DataTables\DataTablesEditor;


class UsersDataTableEditor extends DataTablesEditor

{

    protected $model = User::class;


    /**

     * Get create action validation rules.

     *

     * @return array

     */

    public function createRules()

    {

        return [

            'email' => 'required|email|unique:' . $this->resolveModel()->getTable(),

            'name'  => 'required',

        ];

    }


    /**

     * Get edit action validation rules.

     *

     * @param Model $model

     * @return array

     */

    public function editRules(Model $model)

    {

        return [

            'email' => 'sometimes|required|email|' . Rule::unique($model->getTable())->ignore($model->getKey()),

            'name'  => 'sometimes|required',

        ];

    }

繁星点点滴滴
浏览 79回答 1
1回答

慕虎7371278

在这里找到答案https://www.gitmemory.com/issue/yajra/laravel-datatables-editor/46/552975895views/layouts/app.blade.php,就在</head>之前<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css"/></head>views/layouts/app.blade.php,就在</body>之前<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.js"></script>&nbsp; &nbsp; @stack('scripts')</body>应用程序/DataTables/UsersDataTable.phpreturn $this->builder()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->setTableId('users-table')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->columns($this->getColumns())&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->minifiedAjax()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->dom('Bfrtip')// ---------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->select(true)//---------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->orderBy(1)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->buttons(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button::make('create')->editor('editor'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button::make('edit')->editor('editor'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button::make('remove')->editor('editor'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button::make('export'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button::make('print'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button::make('reset'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button::make('reload')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->editor(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Editor::make()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->fields([&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fields\Text::make('name'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fields\Text::make('email'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fields\Password::make('password'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ])//---------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->idSrc(['id'])//---------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );
打开App,查看更多内容
随时随地看视频慕课网APP