我想重写Laravel背包CRUD包的CRUD视图,因为我想对布局做一些小的更改。但显然我不想改变CRUD包本身。有优雅的做法吗?
发布于 2016-09-02 15:54:57
在加载任何视图之前,Laravel的背包将检查您的resources/views/vendor/backpack/crud文件夹,以查看您是否有任何自定义视图。如果没有,它只会加载包中的视图。
如果您想要覆盖 all CRUDS的刀片文件,只需将一个具有正确名称的文件放在正确的文件夹中即可。看看文件在包中的组织方式。
如果您只想为一个CRUD覆盖刀片文件,请使用萨钦解。
发布于 2016-09-02 12:38:47
在扩展Backpack\CRUD\app\Http\Controllers\CrudController的控制器中,需要覆盖要更改的方法,如索引、创建、编辑。所有的方法都在-
Backpack\CRUD\app\Http\Controllers\CrudController所有的方法都在这里。你需要在这里换衣服
public function index()
{
$this->crud->hasAccessOrFail('list');
$this->data['crud'] = $this->crud;
$this->data['title'] = ucfirst($this->crud->entity_name_plural);
// get all entries if AJAX is not enabled
if (! $this->data['crud']->ajaxTable()) {
$this->data['entries'] = $this->data['crud']->getEntries();
}
// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
// $this->crud->getListView() returns 'list' by default, or 'list_ajax' if ajax was enabled
return view('your_view_name', $this->data);
}发布于 2017-09-18 04:41:51
找到一种甚至不必覆盖index()方法的方法,只需在CrudController的安装方法中使用$this->crud->setListView(),例如:
$this->crud->setListView('backpack::crud.different_list', $this->data);因此,它将获得'/resources/views/vendor/backpack/crud/different_list.blade.php‘下的视图,而不是包中的默认视图。
除了setListView(),setEditView()、setCreateView()、setUpdateView()....are也是可用的。希望能帮上忙。
有关更多细节,您可以参考https://laravel-backpack.readme.io/docs/crud-full-api。
// use a custom view for a CRUD operation
$this->crud->setShowView('your-view');
$this->crud->setEditView('your-view');
$this->crud->setCreateView('your-view');
$this->crud->setListView('your-view');
$this->crud->setReorderView('your-view');
$this->crud->setRevisionsView('your-view');
$this->crud->setRevisionsTimelineView('your-view');
$this->crud->setDetailsRowView('your-view');https://stackoverflow.com/questions/39290611
复制相似问题