question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue-select, how-to get $request value in Laravel's controller?

See original GitHub issue

Hi everyone,

Need some help. I am using Laravel 5.4.

Currently I have a standard select dropdown from Laravel Collection as below.

<div class="col-xs-6 form-group{{ $errors->has('product') ? ' has-error' : '' }}">
	<label class="control-label">Product</label>
	{!! Form::select('product', $products, null, ['class' => 'form-control', 'placeholder' => 'Pick a product...']) !!}
	@if ($errors->has('product'))
		<span class="help-block">
			<strong>{{ $errors->first('product') }}</strong>
		</span>
	@endif
</div>

In Laravel, I can get the request for the above using this

$request->product

But when I use your vue-select component

e.g.

<div class="row">
	<div class="col-xs-4">
		<v-select :options="products" :placeholder="placeholder"></v-select>
	</div>
</div>

How can I get the $request value for this field in Laravel controller?

Plus how can I validate vue-select if no value is selected?

Any help? Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
sagalbotcommented, Feb 26, 2017

@ericmachine88, if you’re not submitting your form via ajax, then you’ll have to use a hidden input. vue-select doesn’t contain an actual form input, but you can easily sync the selected option to a hidden input.

<div class="row">
  <div class="col-xs-4">
    <input type="hidden" v-model="product">
    <v-select v-model="product" :options="products" :placeholder="placeholder"></v-select>
  </div>
</div>
new Vue({
  data: {
    product: null,
    products: [],
    placeholder: null
  }
})

If you’re using vue-validator, you will want to validate the hidden input, not vue-select. On the Laravel side of things, you can just validate the product field as you normally would:

$rules = [
  'product' => 'required'
]
1reaction
sagalbotcommented, Mar 1, 2017

@ericmachine88 didn’t realize vue-validator wasn’t going to have support for v2. I’m sure someone else will build it though if it’s not already out there.

If you get creative with it, there are other ways. I just put together this example that uses a hidden text input to add the required HTML5 attribute.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get the value from v-select using a name attribute ...
I am currently using Vuetify for theming only within a laravel application and do not want to reach into using v-model. Is there...
Read more >
Requests & Input - The PHP Framework For Web Artisans
Getting Only Some Of The Request Input. $input = Input::only('username', 'password');. $input = Input::except('credit_card');.
Read more >
Vue Select get request help - Laracasts
Hi. Im doing my first ajax request that queries the database to retrieve a list of items to use in a dropdown select...
Read more >
How can I populate data which is fetched from API into select ...
Coding example for the question How can I populate data which is fetched from API into select option in Laravel using VueJS and...
Read more >
Vue-Multiselect | Vue Select Library
View on GitHubGetting started & examples ... npm install vue-multiselect --save ... div label.typo__label Single select multiselect( v-model="value", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found