laravel - 重新排序记录显示为空

标签 laravel octobercms

我正在使用OctoberCMS 、Apache 和 PHP7。

我使用生成器创建了一个自定义插件。

我可以添加记录,一切正常。除非我按重新排序记录按钮,否则它会显示空记录列表。


有关于如何设置的指南吗?

我正在看:
https://octobercms.com/docs/database/traits#nested-tree https://octobercms.com/docs/api/october/rain/database/traits/nestedtree

我添加到模型:

使用\October\Rain\Database\Traits\NestedTree;

以及数据库列:

parent_idnest_leftnest_rightnest_深度


我应该在哪里放置$table->integer('parent_id')->nullable();

如果我将其放入模型中,则会出现错误解析错误:语法错误,意外的“$table”(T_VARIABLE),期望函数(T_FUNCTION)


记录

Reorder Records Button


重新排序记录:空列表

Empty Records

最佳答案

首先,您不需要使用nestable,因为我们不处理,而且似乎有一个指南,但很简短。

我们可以对 \October\Rain\Database\Traits\Sortable 进行排序感到满意,因为我们不需要 tree 我们可以跳过添加这些

use \October\Rain\Database\Traits\NestedTree;
parent_id, nest_left, nest_right, nest_depth

如果我们使用trait,则需要一个特定的列名称sort_order,但是如果需要,我们可以通过定义const SORT_ORDER = 'my_sort_order';来更改它 code> 在我们的模型中。

由于您已经构建了表,因此您可以使用构建器插件更新表定义并将sort_order字段添加到表中。

or manually you can use this script and add it to version.yaml file [ plugins\hardiksatasiya\demotest\updates ( respectively in your plugin ) ]

版本.yaml

1.0.19:
    - 'Updated table hardiksatasiya_demotest_sorting'
    - builder_table_update_hardiksatasiya_demotest_sorting_3.php

builder_table_update_hardiksatasiya_demotest_sorting.php

<?php namespace HardikSatasiya\DemoTest\Updates;

use Schema;
use October\Rain\Database\Updates\Migration;

class BuilderTableUpdateHardiksatasiyaDemotestSorting extends Migration
{
    public function up()
    {
        Schema::table('hardiksatasiya_demotest_sorting', function($table)
        {
            $table->integer('sort_order')->default(0)->change();
        });
    }

    public function down()
    {
        Schema::table('hardiksatasiya_demotest_sorting', function($table)
        {
            $table->integer('sort_order')->default(null)->change();
        });
    }
}

Now, add Trait to your Model

<?php namespace HardikSatasiya\DemoTest\Models;

use Model;

/**
 * Model
 */
class Sort extends Model
{
    use \October\Rain\Database\Traits\Validation;
    use \October\Rain\Database\Traits\Sortable;

    ....

现在您可以手动添加所有需要的文件或使用构建器工具。

我更喜欢使用 Builder 添加 Controller 和所需文件

Make sure you tick Reorder behavior

enter image description here

To show name in reorder list, we need to set this property from which field we need to derive a name to show in sorting list.

enter image description here

It will look like this with name as a sort attribute name

enter image description here

Side Menu [ plugin.yaml and controllers]

enter image description here

enter image description here

如果您还有疑问,请评论。

关于laravel - 重新排序记录显示为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50731016/

相关文章:

database - 使用 OctoberCMS Builder 插件将数据从单个表单插入到 2 个不同的表中

javascript - 如何关闭该选项卡? (Octobercms 组件,Javascript)

php - MySQL - 在 Laravel 中以 unix 纪元形式返回日期时间列的空值

php - Laravel 4 - 连接到其他数据库

php - 将 Mysql 附近查询转换为 Laravel API 查询

php - 找不到 Laravel 5 View

laravel - 如何创建 Nova 过滤器以按关系过滤资源?

laravel - 监听事件:User::creating

十月CMS |关闭后端重定向到安全协议(protocol)

php - OctoberCMS db 查询和 json