保存数组值而不是 select 形式的索引

Save array value instead of index from select form

我的控制器 $status=array('Ended', 'Processing', 'Canceled'); 中有这个数组,我通过 return view('Form.FormEdit')->with('status', $status) 将它发送到我的视图。

在select中显示了每个索引中包含的值 {{Form::select('status', $status, null, array('class'=>'form-control', 'placeholder'=>'Select status'))}} 但它保存了索引号,我不想要那个。

希望大家能帮帮我,谢谢

在控制器中你可以创建如下数组并传递给视图:

$status=[
    'Ended' => 'Ended',
    'Processing' => 'Processing',
    'Canceled' => 'Canceled'
];

return view('Form.FormEdit')->with('status', $status)

如果你想保存文本,你需要有一个带有文本键的数组。现在,您的数组只是一个索引数组 (0, 1, 2 ...)。

你可以使用这个:

return view('Form.FormEdit')->with('status', array_combine($status, $status));