0

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?

Dees Oomens
  • 4,554
  • 3
  • 29
  • 61
Rohullah Rajaee Rad
  • 571
  • 2
  • 9
  • 33

1 Answers1

0

You can do it like this :

return $this->with('index')->find($id)->pluck('index.indexField');
Maraboc
  • 10,550
  • 3
  • 37
  • 48
  • return $this->with('index')->find($id)->pluck('index.id', 'index.code');//Erorr: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'index.id' in 'field list' (SQL: select `index`.`id` from `positions`) – Rohullah Rajaee Rad Aug 01 '17 at 10:23
  • Can you print the structure of what you get after calling `getById` ? – Maraboc Aug 01 '17 at 10:37