Laravel - Populating Select List with Derived Values

后端 未结 2 1596
梦如初夏
梦如初夏 2021-01-28 12:46

I have an Eloquent model (Presenters) that has three columns: id, first_name and last_name. What I want to do is populate the select opti

相关标签:
2条回答
  • 2021-01-28 13:27

    You've provided the answer, look at the PaulDM reply

    Just adapt it, hope it works for you:

    // your eloquent model ...
    public static function listPresenters() {
        $ret = [];
        foreach (self::all() as $presenter) {
            $ret[$presenter->id] = "{$presenter->first_name} {$presenter->last_name}";
        }
        return $ret;
    }
    // your eloquent model ...
    
    0 讨论(0)
  • 2021-01-28 13:45
    Presenter::select('id', DB::raw('CONCAT(first_name, " ", last_name) AS full_name'))->lists('full_name', 'id');
    
    0 讨论(0)
提交回复
热议问题