正如这里所建议的,我创建了 app/Models/Page.php。我在$fillable
.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
use Cviebrock\EloquentSluggable\Sluggable;
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
use Backpack\PageManager\app\Models\Page as OriginalPageModel;
class Page extends OriginalPageModel
{
use CrudTrait;
use Sluggable;
use SluggableScopeHelpers;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
protected $table = 'pages';
protected $primaryKey = 'id';
public $timestamps = true;
// protected $guarded = ['id'];
protected $fillable = ['template', 'name', 'title', 'slug',
'content1-header', 'content1','content2-header','content2',
'content3-header','content3','content4-header','content4',
'content5-header','content5','content6-header','content6', 'extras'];
// protected $hidden = [];
// protected $dates = [];
protected $fakeColumns = ['extras'];
...
...
}
并创建了 app/Http/Controllers/Admin/PageCrudController.php 与示例相同的代码。
<?php namespace App\Http\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\PageManager\app\Http\Controllers\Admin\PageCrudController as OriginalPageCrudController;
use App\PageTemplates;
// VALIDATION: change the requests to match your own file names if you need form validation
use Backpack\PageManager\app\Http\Requests\PageRequest as StoreRequest;
use Backpack\PageManager\app\Http\Requests\PageRequest as UpdateRequest;
class PageCrudController extends OriginalPageCrudController {
public function __construct($template_name = false)
{
/*
|--------------------------------------------------------------------------
| BASIC CRUD INFORMATION
|--------------------------------------------------------------------------
*/
$this->crud->setModel("App\Models\Page");
$this->crud->setRoute(config('backpack.base.route_prefix').'/page');
$this->crud->setEntityNameStrings('page', 'pages');
/*
|--------------------------------------------------------------------------
| COLUMNS
|--------------------------------------------------------------------------
*/
$this->crud->addColumn('name');
$this->crud->addColumn([
'name' => 'template',
'type' => 'model_function',
'function_name' => 'getTemplateName',
]);
$this->crud->addColumn('slug');
/*
|--------------------------------------------------------------------------
| FIELDS
|--------------------------------------------------------------------------
*/
// In PageManager,
// - default fields, that all templates are using, are set using $this->addDefaultPageFields();
// - template-specific fields are set per-template, in the PageTemplates trait;
/*
|--------------------------------------------------------------------------
| BUTTONS
|--------------------------------------------------------------------------
*/
$this->crud->addButtonFromModelFunction('line', 'open', 'getOpenButton', 'beginning');
}
public function store(StoreRequest $request)
{
return parent::storeCrud();
}
public function update(UpdateRequest $request)
{
return parent::updateCrud();
}
}
并修改了app/PageTemplates.php
...
...
private function page()
{
$this->crud->addField([ // CustomHTML
'name' => 'metas_separator',
'type' => 'custom_html',
'value' => '<br><h2>Metas</h2><hr>',
]);
...
...
$this->crud->addField([ // CustomHTML
'name' => 'content_separator',
'type' => 'custom_html',
'value' => '<br><h2>Content</h2><hr>',
]);
$this->crud->addField([
'name' => 'content1-header',
'label' => 'Content 1 Header',
'type' => 'text',
'placeholder' => 'Your content here',
]);
$this->crud->addField([
'name' => 'content1',
'label' => 'Content 1',
'type' => 'wysiwyg',
'placeholder' => 'Your content here',
]);
$this->crud->addField([
'name' => 'content2-header',
'label' => 'Content 2 Header',
'type' => 'text',
'placeholder' => 'Your content here',
]);
$this->crud->addField([
'name' => 'content2',
'label' => 'Content 2',
'type' => 'wysiwyg',
'placeholder' => 'Your content here',
]);
$this->crud->addField([
'name' => 'content3-header',
'label' => 'Content 3 Header',
'type' => 'text',
'placeholder' => 'Your content here',
]);
$this->crud->addField([
'name' => 'content3',
'label' => 'Content 3',
'type' => 'wysiwyg',
'placeholder' => 'Your content here',
]);
...
...
但是,它不会更新或插入数据。我在这里做错了什么?