如何将数据放入查看列表页面?

时间:2019-02-04 16:00:23

标签: backpack-for-laravel

我有一个控制器:

class PageCrudController extends CrudController
{

    public function search()
    {
        $res = parent::search();
        return $res;
    }

    public function setup()
    {
        /*
        |--------------------------------------------------------------------------
        | CrudPanel Basic Information
        |--------------------------------------------------------------------------
        */
        $this->crud->setModel('App\Models\Page');
        $this->crud->setRoute(config('backpack.base.route_prefix') . '/page');
        $this->crud->setEntityNameStrings('page', 'pages');
        $this->crud->setListView('vendor.backpack.crud.page.list');
        $this->search();

        /*
        |--------------------------------------------------------------------------
        | CrudPanel Configuration
        |--------------------------------------------------------------------------
        */

        // Select all roots elements with their children
        $pagesTree = collect([]);

        $roots = Page::where('parent_id', null)->get();

        $roots->each(function ($value) use(&$pagesTree) {
            $tree = $value->getDescendantsAndSelf();
            $pagesTree = $pagesTree->merge($tree);
        });

在控制器中,我有变量$pagesTree。它包含排序的数据。我需要在列表的查看页面上显示它,而不是默认数据。

$this->crud->orderBy不适合。如您所见,由于这里有特殊的项目顺序。我在此软件包https://github.com/etrepat/baum#inserting-nodes的帮助下得到了它。

0 个答案:

没有答案