Laravel - Form Input - Multiple select for a one to many relationship

后端 未结 7 1006
情深已故
情深已故 2021-02-01 04:40

One of the requirements in an application that I am building is for a form input which takes in a varying number of items for a single field. For instance, sports that I play ar

7条回答
  •  忘了有多久
    2021-02-01 04:49

    A multiple select is really just a select with a multiple attribute. With that in mind, it should be as easy as...

    Form::select('sports[]', $sports, null, array('multiple'))
    

    The first parameter is just the name, but post-fixing it with the [] will return it as an array when you use Input::get('sports').

    The second parameter is an array of selectable options.

    The third parameter is an array of options you want pre-selected.

    The fourth parameter is actually setting this up as a multiple select dropdown by adding the multiple property to the actual select element..

提交回复
热议问题