Populate select element

梦想的初衷 提交于 2019-12-05 16:05:28

You could use the lists(string $column [, string $key ]) method for this, found under "Retrieving A List Of Column Values" in the documentation...

$catlist = Category::where('type', $content_type)->lists('name');

try to add static function on you category model

public static function genlist()
{
    $catlist = [];
    foreach (self::all() as $cat)
    {
        $catlist[$cat->id] = $cat->name;
    }
    return $catlist;
}

view

{{ Form::select('cat_id', Category::genlist()) }}

this works to me, and hope will work to you also

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!