Please help me guys, i have a problem when i try to make a dropdown list using pluck function.
this is my controller code
public function tambah()
{
$jabatan = jabatan::pluck('nama_jab', 'id_jab')->toArray();
return view('anggota.tambah',compact('jabatan'));
}
and this is my view code
<div class="form-group">
<label class="col-sm-2 control-label" id="ruangan_id">Jabatan</label>
<div class="col-sm-10">
{!! Form::select('id_jab',$jabatan,null,['class'=>'form-control','id_jab'=>'id_jab','placeholder'=>"Jabatan"]) !!}
</div>
this is model for jabatan
protected $table=['jabatan'];
public function anggota(){
return $this->hasMany('App\anggota');
}
this is model for anggota
protected $table = 'anggota';
protected $guarded=['id'];
public function jabatan(){
return $this->belongsTo('App\jabatan');
}
i want to show this data to my dropdown list
id_jab nama_jab
1 manager
2 ka.divisi
3 staff
4 pekerja
end the error message:
ErrorException in Grammar.php line 36: Array to string conversion
please help me
Instead of:
$jabatan = jabatan::pluck('nama_jab', 'id_jab')->toArray();
use:
$jabatan = jabatan::pluck('nama_jab', 'id_jab');
Or:
$jabatan = jabatan::get()->pluck('nama_jab', 'id_jab');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.