Created
April 16, 2017 08:24
-
-
Save the94air/7e7642e381bb7d5a55cbfa07b954db0c to your computer and use it in GitHub Desktop.
Use normal html select in Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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