Rohullah Rajaee Rad
Rohullah Rajaee Rad

Reputation: 581

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

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?

Upvotes: 0

Views: 218

Answers (1)

Maraboc
Maraboc

Reputation: 11083

You can do it like this :

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

Upvotes: 0

Related Questions