我正在使用Serverfireteam LaravelPanel(使用zofe / rapyd-laravel) )。我为一个实体创建了一个crud控制器。此实体具有另一个表的外键。现在我想显示这个外键的自动完成功能,但它只显示一个空的选择框。
我的Controller代码如下所示:
public function edit($entity){
parent::edit($entity);
$this->edit = \DataEdit::source(new \App\Regal());
$this->edit->add('bezeichnung', 'Bezeichnung','text');
$this->edit->add('nummer', 'Nummer','text');
$this->edit->add('maxPaletten', 'Max Paletten je Ebene','text');
$this->edit->add('anzahlEbenen', 'Anzahl Ebenen','text');
$this->edit->add('kunde_id','Kunde','select')->options(\App\Kunde::lists("name", "id"));
return \View::make('regale.editPanel', array(
'title' => $this->entity ,
'edit' => $this->edit
));
}
我的模型文件:
class Kunde extends Model {
protected $table = 'kunden';
public function listPaletten(){
return $this->hasMany('App\Models\Palette');
}
public function listAdressen(){
return $this->hasMany('App\Models\Adresse');
}
public function listRegale(){
return $this->hasMany('App\Models\Regal');
}
public function listArtikel(){
return $this->hasMany('App\Models\Artikel');
}
}
...
class Regal extends Model {
protected $table = 'regale';
public function kunde(){
return $this->belongsTo('App\Models\Kunde');
}
}
答案 0 :(得分:1)
您正在使用选项方法,选项方法用于选择框。
正如document:
中所述autocomplete(使用twitter typeahead的自动完成功能的输入字段和使用relation.fieldname和search()方法的ajax功能)
$this->edit->add('author.fullname', 'Author', 'autocomplete')->search(array('firstname', 'lastname'));