Laravel - Populating Select List with Derived Values

后端 未结 2 1599
梦如初夏
梦如初夏 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 ...
    

提交回复
热议问题