Search code examples
arrayslaravellaravelcollective

Save array value instead of index from select form


I have this array in my controller $status=array('Ended', 'Processing', 'Canceled'); and I send it by return view('Form.FormEdit')->with('status', $status) to my view.

In the select it shows the values contained in each index {{Form::select('status', $status, null, array('class'=>'form-control', 'placeholder'=>'Select status'))}} but it saves the index number and I don't want that.

I hope you can help me, thanks.


Solution

  • in controller you can make array like below and pass to view:

    $status=[
        'Ended' => 'Ended',
        'Processing' => 'Processing',
        'Canceled' => 'Canceled'
    ];
    
    return view('Form.FormEdit')->with('status', $status)