如何在Laravel 5中翻译馆藏? [英] How to translate collections in Laravel 5?

查看:86
本文介绍了如何在Laravel 5中翻译馆藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 pluck方法来检索值.如何转换这些值? (这些值是选择输入字段的选项)

I am using the pluck method to retrieve values. How can I translate these values? (these values are options for a selection input field)

$relationtypes = Relationtype::pluck('name', 'id');

我的关系类型是:供应商,客户等.

My relationtypes are: supplier, customer, etc.

推荐答案

我还找到了一个更方便的解决方案:

I also found a more convenient solution:

$relationtypes = RelationType::pluck('name', 'id')->map(function ($item, $key) {
    return trans('labels.' . $item . '');
});

将此内容传递给视图,您可以使用:

Passing this to your view, you can use:

{!! Form::select('relationtypes[]', $relationtypes, 
    isset($relation) ? $relation->relationtypes->pluck('id')->toArray() : 0, ['class' => 'form-control']) !!}

希望这对其他人有帮助!

Hope this helps other people!

这篇关于如何在Laravel 5中翻译馆藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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