2017-07-12 63 views
0

我試圖追加一個字符串到Laravel選擇菜單的選項值。如何將字符串追加到Laravel 5.1選擇菜單選項值

控制器:

$anytimeMinutesList = Models\Tariff::has('deals')->where('anytime_minutes', '>', '0') 
        ->groupBy('anytime_minutes')->orderBy('anytime_minutes', 'asc') 
        ->lists('anytime_minutes', 'anytime_minutes'); 
$anytimeMinutesList->prepend('No minutes', '0'); 
$anytimeMinutesList->prepend('Any minutes', ''); 

查看:

{!! Form::select('anytime_minutes', $anytimeMinutesList, Input::get('anytime_minutes'), 
['class' => 'form-control']) !!} 

請檢查Result

我希望能夠在字符串 '分鐘' 添加到每個選擇的菜單的選項值,以便它們讀取:

  • 200分鐘
  • 250分鐘
  • 300分鐘

等等

回答

0

我只想用一個簡單的array_map這裏:

{!! Form::select('anytime_minutes', 
    array_map(function($val){ 
    return $val . ' minutes'; 
    }, $anytimeMinutesList), 
    Input::get('anytime_minutes'), 
    ['class' => 'form-control']) !!} 
0

感謝您的答覆。代碼有幾個問題。但是,我設法得到以下產生所需的輸出:

{!! Form::select('anytime_minutes', 
    array_map(function($val) { 
     return $val . ' minutes'; 
    }, $anytimeMinutesList->toArray())) !!}