添加项目到选择框与一个雄辩的集合 [英] Add item to select box with an Eloquent collection

查看:86
本文介绍了添加项目到选择框与一个雄辩的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单上有一个选择框,该选择框使用来自Eloquent模型(Laravel 4)列出的数据:

I have a select box on a form which uses data that is listed from an Eloquent model (Laravel 4):

$campuses = Campus::lists('name', 'id');

表单:

{{ Form::select('campus_id', $campuses) }}

然而,我希望表单上的第一个选项是选择... ,以便当用户尚未选择选项时,第一个选项不成为默认值。

However, I would like to have the first option on the form be Select... so that when the user has not selected an option yet, the first option does not become the default.

我如何在Eloquent集合的开头添加另一个选项?

How can I prepend another option to the beginning of the Eloquent collection?

我尝试过如下:

$campuses = array('Select...') . Campus::lists('name', 'id');


推荐答案

你也可以做

$campuses = array('' => 'Select...') + Campus::lists('name', 'id');

这是我使用的方式,sum 2数组

This is the way I use it, sum 2 arrays

这篇关于添加项目到选择框与一个雄辩的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆