Unable to Pass Variable from Controller to Drop Down
up vote
0
down vote
favorite
I'm trying to get data from a table called solutions and view the solution names in a dropdown list on a form called products.
I've created a provider called DynamicDropdown in App/Providers.
<?php
namespace AppProviders;
use AppDropdown;
use IlluminateSupportServiceProvider;
class DynamicDropdown extends ServiceProvider
{
public function boot()
{
view()->composer('*', function ($view) {
$view->with('product_array', Dropdown::all());
});
}
}
Controller
<?php
namespace AppHttpControllers;
use AppHttpRequests;
use AppHttpControllersController;
use AppProvidersDynamicDropdown;
use AppProduct;
use IlluminateHttpRequest;
class ProductsController extends Controller
{
public function index(Request $request)
{
$select = ;
foreach ($view as $data) {
$select [$data->id] = $data->solutionname;
}
return view('products.products', compact('select'));
}
}
I've called the select variable in the view but unfortunately, I'm getting an undefined variable error.
Blade
<div class="form-group <?php echo e($errors->has('solution') ? 'has-error' : ''); ?>">
<?php echo Form::label('solution', 'Solution', ['class' => 'control-label']); ?>
<?php echo Form::select('solution', $select, null,
('' == 'required') ? ['class' => 'form-control', 'required' => 'required'] : ['class' => 'form-control']); ?>
<?php echo $errors->first('solution', '<p class="help-block">:message</p>'); ?>
</div>
Error Message is...
ErrorException thrown with message "Undefined variable: select (View:
E:LaravelIBMintresourcesviewsproductsproductsform.blade.php)
I tried many ways to fix it. But still could not find a solution. Appreciate if someone could assist.
Thank You.
laravel laravel-blade laravel-5.7 laravelcollective
add a comment |
up vote
0
down vote
favorite
I'm trying to get data from a table called solutions and view the solution names in a dropdown list on a form called products.
I've created a provider called DynamicDropdown in App/Providers.
<?php
namespace AppProviders;
use AppDropdown;
use IlluminateSupportServiceProvider;
class DynamicDropdown extends ServiceProvider
{
public function boot()
{
view()->composer('*', function ($view) {
$view->with('product_array', Dropdown::all());
});
}
}
Controller
<?php
namespace AppHttpControllers;
use AppHttpRequests;
use AppHttpControllersController;
use AppProvidersDynamicDropdown;
use AppProduct;
use IlluminateHttpRequest;
class ProductsController extends Controller
{
public function index(Request $request)
{
$select = ;
foreach ($view as $data) {
$select [$data->id] = $data->solutionname;
}
return view('products.products', compact('select'));
}
}
I've called the select variable in the view but unfortunately, I'm getting an undefined variable error.
Blade
<div class="form-group <?php echo e($errors->has('solution') ? 'has-error' : ''); ?>">
<?php echo Form::label('solution', 'Solution', ['class' => 'control-label']); ?>
<?php echo Form::select('solution', $select, null,
('' == 'required') ? ['class' => 'form-control', 'required' => 'required'] : ['class' => 'form-control']); ?>
<?php echo $errors->first('solution', '<p class="help-block">:message</p>'); ?>
</div>
Error Message is...
ErrorException thrown with message "Undefined variable: select (View:
E:LaravelIBMintresourcesviewsproductsproductsform.blade.php)
I tried many ways to fix it. But still could not find a solution. Appreciate if someone could assist.
Thank You.
laravel laravel-blade laravel-5.7 laravelcollective
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to get data from a table called solutions and view the solution names in a dropdown list on a form called products.
I've created a provider called DynamicDropdown in App/Providers.
<?php
namespace AppProviders;
use AppDropdown;
use IlluminateSupportServiceProvider;
class DynamicDropdown extends ServiceProvider
{
public function boot()
{
view()->composer('*', function ($view) {
$view->with('product_array', Dropdown::all());
});
}
}
Controller
<?php
namespace AppHttpControllers;
use AppHttpRequests;
use AppHttpControllersController;
use AppProvidersDynamicDropdown;
use AppProduct;
use IlluminateHttpRequest;
class ProductsController extends Controller
{
public function index(Request $request)
{
$select = ;
foreach ($view as $data) {
$select [$data->id] = $data->solutionname;
}
return view('products.products', compact('select'));
}
}
I've called the select variable in the view but unfortunately, I'm getting an undefined variable error.
Blade
<div class="form-group <?php echo e($errors->has('solution') ? 'has-error' : ''); ?>">
<?php echo Form::label('solution', 'Solution', ['class' => 'control-label']); ?>
<?php echo Form::select('solution', $select, null,
('' == 'required') ? ['class' => 'form-control', 'required' => 'required'] : ['class' => 'form-control']); ?>
<?php echo $errors->first('solution', '<p class="help-block">:message</p>'); ?>
</div>
Error Message is...
ErrorException thrown with message "Undefined variable: select (View:
E:LaravelIBMintresourcesviewsproductsproductsform.blade.php)
I tried many ways to fix it. But still could not find a solution. Appreciate if someone could assist.
Thank You.
laravel laravel-blade laravel-5.7 laravelcollective
I'm trying to get data from a table called solutions and view the solution names in a dropdown list on a form called products.
I've created a provider called DynamicDropdown in App/Providers.
<?php
namespace AppProviders;
use AppDropdown;
use IlluminateSupportServiceProvider;
class DynamicDropdown extends ServiceProvider
{
public function boot()
{
view()->composer('*', function ($view) {
$view->with('product_array', Dropdown::all());
});
}
}
Controller
<?php
namespace AppHttpControllers;
use AppHttpRequests;
use AppHttpControllersController;
use AppProvidersDynamicDropdown;
use AppProduct;
use IlluminateHttpRequest;
class ProductsController extends Controller
{
public function index(Request $request)
{
$select = ;
foreach ($view as $data) {
$select [$data->id] = $data->solutionname;
}
return view('products.products', compact('select'));
}
}
I've called the select variable in the view but unfortunately, I'm getting an undefined variable error.
Blade
<div class="form-group <?php echo e($errors->has('solution') ? 'has-error' : ''); ?>">
<?php echo Form::label('solution', 'Solution', ['class' => 'control-label']); ?>
<?php echo Form::select('solution', $select, null,
('' == 'required') ? ['class' => 'form-control', 'required' => 'required'] : ['class' => 'form-control']); ?>
<?php echo $errors->first('solution', '<p class="help-block">:message</p>'); ?>
</div>
Error Message is...
ErrorException thrown with message "Undefined variable: select (View:
E:LaravelIBMintresourcesviewsproductsproductsform.blade.php)
I tried many ways to fix it. But still could not find a solution. Appreciate if someone could assist.
Thank You.
laravel laravel-blade laravel-5.7 laravelcollective
laravel laravel-blade laravel-5.7 laravelcollective
edited Nov 11 at 8:04
Karl Hill
1,9311736
1,9311736
asked Nov 11 at 6:22
Trey Wayne
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
It is because you are actually calling the $select variable on the wrong form. You return a view
return view('products.products', compact('select'));
which means get the view products.blade.php on the folder products under the view folder.
and based on the error you put the $select variable on the form.blade.php.
Fix will be you return the view form.blade.php like this.
return view('products.products.form', compact('select'));
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
It is because you are actually calling the $select variable on the wrong form. You return a view
return view('products.products', compact('select'));
which means get the view products.blade.php on the folder products under the view folder.
and based on the error you put the $select variable on the form.blade.php.
Fix will be you return the view form.blade.php like this.
return view('products.products.form', compact('select'));
add a comment |
up vote
0
down vote
It is because you are actually calling the $select variable on the wrong form. You return a view
return view('products.products', compact('select'));
which means get the view products.blade.php on the folder products under the view folder.
and based on the error you put the $select variable on the form.blade.php.
Fix will be you return the view form.blade.php like this.
return view('products.products.form', compact('select'));
add a comment |
up vote
0
down vote
up vote
0
down vote
It is because you are actually calling the $select variable on the wrong form. You return a view
return view('products.products', compact('select'));
which means get the view products.blade.php on the folder products under the view folder.
and based on the error you put the $select variable on the form.blade.php.
Fix will be you return the view form.blade.php like this.
return view('products.products.form', compact('select'));
It is because you are actually calling the $select variable on the wrong form. You return a view
return view('products.products', compact('select'));
which means get the view products.blade.php on the folder products under the view folder.
and based on the error you put the $select variable on the form.blade.php.
Fix will be you return the view form.blade.php like this.
return view('products.products.form', compact('select'));
answered Nov 11 at 15:11
Dearwolves
169113
169113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246364%2funable-to-pass-variable-from-controller-to-drop-down%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown