Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a select for foreign key object serverfireteam/panel

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');        
}
}
like image 266
Thomas Kaemmerling Avatar asked Nov 10 '22 08:11

Thomas Kaemmerling


1 Answers

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'));
like image 96
Alireza Aboutalebi Avatar answered Nov 14 '22 22:11

Alireza Aboutalebi