如何在背囊背包中覆盖动作方法而又不丢失其功能

问题描述 投票:0回答:1

我想在laravel背包中覆盖一个动作方法而又不失去其功能。

我正在尝试

use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation\ {index as traitIndex };

use Backpack\CRUD\app\Http\Controllers\CrudController;

class ApplicationCrudController extends CrudController
{

  public function setup() {...}

  // trying to override using the functionality
  public function index() {
    parent::traitIndex();
  }
}

我想使用$ this-> crud-> setHeading('some string','create');设置标题。进入索引方法。

有什么想法吗?

非常感谢

laravel backpack-for-laravel
1个回答
0
投票

一分钟前,我尝试了这个并且工作了。

use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation\  // I deleted this {index as traitIndex };

use Backpack\CRUD\app\Http\Controllers\CrudController;

class ApplicationCrudController extends CrudController
{

    // Add this
    use ListOperation {
        index as traitIndex;
    }

  public function setup() {...}

  // trying to override using the functionality
  public function index() {
    // delete this parent::traitIndex();
    // and add this
    return $this->traitIndex();
  }
}


谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.