2016-09-02 150 views
3

我想重写Laravel Backpack CRUD包的CRUD视图,因为我想对布局进行小的更改。但显然我不想更改CRUD包本身。有这样做的优雅吗?覆盖CRUD视图

回答

2

改变加载任何意见之前,背包Laravel检查您resources/views/vendor/backpack/crud文件夹,看看如果您有任何自定义视图。如果你不这样做,它只会加载包中的视图。

如果要覆盖一个刀片文件所有 CRUDS,你可以把一个文件在正确的文件夹中的正确的名称。看看how the files are organized in the package

如果您想为一个CRUD覆盖刀片文件,请使用Sachin's solution

+0

工程就像一个魅力,谢谢。 –

5

在您的控制器正在扩展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); 
} 
+0

你能评论一下你创建的文件名和路径吗?如果这是更新书籍模型记录,那么刀片模板是否位于'/ resources/views/vendor/backpack/crud/book/edit.blade.php'中?我还没有完成它。 – Dubby

+0

我解决了它。在我的情况下,我想编辑课程记录,所以我在'/ resources/views/course/edit.blade.php'中创建了一个文件,并用'view('course.edit')'调用了这个文件。 – Dubby

0

发现甚至没有覆盖指数()方法, 只使用$这 - 办法> crud-> setListView()在你的CrudController,当然你的设置方法:

$this->crud->setListView('backpack::crud.different_list', $this->data); 

因此,它将获取 '/resources/views/vendor/backpack/crud/different_list.blade.php'中的视图,而不是包中的默认视图。

除了setListView(),setEditView(),setCreateView(),setUpdateView()....也可用。希望能帮助到你。

有关更多详细信息,请参阅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');