Skip to content

Instantly share code, notes, and snippets.

@the94air
Created April 16, 2017 08:24
Show Gist options
  • Save the94air/7e7642e381bb7d5a55cbfa07b954db0c to your computer and use it in GitHub Desktop.
Save the94air/7e7642e381bb7d5a55cbfa07b954db0c to your computer and use it in GitHub Desktop.
Use normal html select in Laravel
<?php
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$tags = Tag::select('name', 'id')->get(); // <------- This is very !important
return view('posts.create')->withTags($tags);
}
?>
<!-- in the view instead of this
{{ Form::label('tags', 'Tags') }}
{{ Form::select('tags[]', $tags, null, ['multiple' => '', 'class' => 'form-control tags', 'required' => '']) }}
More info
https://laravel.com/docs/5.4/queries#selects
https://goo.gl/oBBVAo
-->
<select name="tags[]" id="tags" class="form-control tags" multiple required>
@foreach($tags as $tag)
<option value="{{ $tag->id }}">{{ $tag->name }}</option>
@endforeach
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment