我想从数据库创建动态组合框,但我有一条错误消息:
CrudTrait.php 第 32 行中的 ErrorException:未定义偏移量:0(查看:/home/vagrant/Code/hrd/resources/views/vendor/backpack/crud/fields/select2.blade.php)(查看:/home/vagrant/代码/hrd/resources/views/vendor/backpack/crud/fields/select2.blade.php)(查看:/home/vagrant/Code/hrd/resources/views/vendor/backpack/crud/fields/select2.blade。 php)
这是我的 DistrictCrudController.php :
<?php
namespace App\Http\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use App\Http\Requests\DistrictRequest as StoreRequest;
use App\Http\Requests\DistrictRequest as UpdateRequest;
class DistrictCrudController extends CrudController {
public function __construct() {
parent::__construct();
$this->crud->setModel("App\Models\District");
$this->crud->setRoute("admin/district");
$this->crud->setEntityNameStrings('district', 'districts');
$this->crud->setFromDb();
$this->crud->addField([
'label' => "City",
'type' => 'select2',// the method that defines the relationship in your Model
'name' => 'city_id', // the db column for the foreign key
'entity' => 'cities', //tabel entity
'attribute' => 'id', // foreign key attribute that is shown to user
'model' => "App\Models\City" // foreign key model
]);
}
public function store(StoreRequest $request)
{
return parent::storeCrud();
}
public function update(UpdateRequest $request)
{
return parent::updateCrud();
}
}
如果我删除,代码运行良好:
$this->crud->addField([
'label' => "City",
'type' => 'select2',// the method that defines the relationship in your Model
'name' => 'city_id', // the db column for the foreign key
'entity' => 'cities', //tabel entity
'attribute' => 'id', // foreign key attribute that is shown to user
'model' => "App\Models\City" // foreign key model
]);
我使用 Laravel 5.2 的背包