【发布时间】:2017-11-16 06:26:41
【问题描述】:
嗨,我有代码说明
$users = User::all();
但我只想要集合中用户的电子邮件地址。所以我尝试了:
$users = User::select('id', 'email')->first();
这不能如我所愿。当我执行 var_dump 时,我只想查看用户的电子邮件地址。有小费吗?
更新:我也插入了刀片代码。我使用具有下拉菜单的 Vue 组件,并在 Vue 方法中过滤数据并将过滤后的数据插入到 userEmail 下:
组件:
<commands-component
:entity-config="commandConfig(command.id, command.signature, command.hasUser, command.title, command.groupID, command.groupName)">
<input style="margin-right:10px;margin-bottom:10px;" type="button" class="btn btn-primary" v-bind:value="command.title" v-on:click='disableEmailText(command.hasUser)'>
</commands-component>
Vue:
var systemadmin = new Vue({
el: "#sysadmin",
data: function() {
return {
users: <?php echo $users ?>,
userData: [],
commands: <?php echo $commands ?>,
}
},
methods: {
commandConfig: function(ident, signature, hasUser, title, groupId, groupName){
var that = this;
var commandsGetUsers = [];
commandsGetUsers = _.map(that.users, function(value) {
var newValue = {};
newValue.value = value.id;
newValue.text = value.email;
return newValue;
});
return {
id: { text: 'commandModal' + ident, id: null },
modalTitle: title,
buttons: [
{
buttonTitle: 'Run Command',
buttonClass: 'btn btn-success pull-right',
submitUrl: {
url: '/admin/artisan/commands/run',
},
}
],
attributes: [
{name: "message", displayName: "Are you sure you want to proceed with the command?", type: "action-text", col: "12" },
{name: "signature", displayName: "Command Signature", type:'text', col:"6"},
{name: "userEmail", displayName: "Users", type: 'select', options: commandsGetUsers, col:'6'}
],
data: {
signature:signature,
hasUser:hasUser
}
};
},
【问题讨论】:
-
所有用户或单个用户的电子邮件?你能详细说明一下吗?
-
所有用户的电子邮件地址:)
-
使用 pluck
$users = User::pluck('email')->toArray();将所有用户的电子邮件作为数组检索。 -
@Rits 然后它在我的刀片模板上给了我错误 - 数组到字符串的转换。我正在使用用户电子邮件来填充下拉列表
标签: php laravel collections orm