I'm using the Serverfireteam LaravelPanel (which uses zofe/rapyd-laravel ). I created a crud controller for an entity. This entity has a foreign key to another table. Now i want to show an autocomplete for this foreign key but it shows just an empty selectbox.
my Controller code look like this:
 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
        )); 
}    
And my Model files:
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');        
}
}
                You are using options method, options method is used for selectbox .
As it is explained in the document :
autocomplete (input field with autocomplete feature using twitter typeahead and ajax features using relation.fieldname and search() method )
$this->edit->add('author.fullname', 'Author', 'autocomplete')->search(array('firstname', 'lastname'));
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With