Unable to Pass Variable from Controller to Drop Down












0














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.










share|improve this question





























    0














    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.










    share|improve this question



























      0












      0








      0







      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 8:04









      Karl Hill

      2,17311740




      2,17311740










      asked Nov 11 at 6:22









      Trey Wayne

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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'));





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            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

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            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'));





            share|improve this answer


























              0














              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'));





              share|improve this answer
























                0












                0








                0






                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'));





                share|improve this answer












                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'));






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 15:11









                Dearwolves

                199113




                199113






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    這個網誌中的熱門文章

                    Academy of Television Arts & Sciences

                    L'Équipe

                    1995 France bombings