Laravel5.3:How to use pluck in relationship for bindign Form::select element?

227 Views Asked by At

This is my model:

class Positions extends Model implements Repository
{
    protected $fillable = ['index_id', 'title', 'description'];

    public function index()
    {
        return $this->belongsTo('TEST\Indices', 'index_id');
    }

    public function getById($id)
    {
        return $this->with('index')->find($id);
    }
}

how to use pluck() in getById() function for listing index relationship?

1

There are 1 best solutions below

2
On

You can do it like this :

return $this->with('index')->find($id)->pluck('index.indexField');