Laravel Populate Drop-down list of countries using Form Collective using array





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Im new to laravel and I want to populate my dropdown list using Form Collectives in Laravel




Fore example, Here is my array of countries




<?php 
$countries = array("AF" => "Afghanistan",
"AL" => "Albania",
"DZ" => "Algeria",
"AS" => "American Samoa",
"AD" => "Andorra",
"AO" => "Angola")
?>


Here is my Form-Collective "Select / Dropdown"




Using Form Collective




   {{Form::select('country',  '', null, ['class' => 'form-control', 'placeholder' => 'Select Country...'])}}


So how can i do it? Anyone who would like to help me, I appreciate it thank you!










share|improve this question





























    0















    Im new to laravel and I want to populate my dropdown list using Form Collectives in Laravel




    Fore example, Here is my array of countries




    <?php 
    $countries = array("AF" => "Afghanistan",
    "AL" => "Albania",
    "DZ" => "Algeria",
    "AS" => "American Samoa",
    "AD" => "Andorra",
    "AO" => "Angola")
    ?>


    Here is my Form-Collective "Select / Dropdown"




    Using Form Collective




       {{Form::select('country',  '', null, ['class' => 'form-control', 'placeholder' => 'Select Country...'])}}


    So how can i do it? Anyone who would like to help me, I appreciate it thank you!










    share|improve this question

























      0












      0








      0








      Im new to laravel and I want to populate my dropdown list using Form Collectives in Laravel




      Fore example, Here is my array of countries




      <?php 
      $countries = array("AF" => "Afghanistan",
      "AL" => "Albania",
      "DZ" => "Algeria",
      "AS" => "American Samoa",
      "AD" => "Andorra",
      "AO" => "Angola")
      ?>


      Here is my Form-Collective "Select / Dropdown"




      Using Form Collective




         {{Form::select('country',  '', null, ['class' => 'form-control', 'placeholder' => 'Select Country...'])}}


      So how can i do it? Anyone who would like to help me, I appreciate it thank you!










      share|improve this question














      Im new to laravel and I want to populate my dropdown list using Form Collectives in Laravel




      Fore example, Here is my array of countries




      <?php 
      $countries = array("AF" => "Afghanistan",
      "AL" => "Albania",
      "DZ" => "Algeria",
      "AS" => "American Samoa",
      "AD" => "Andorra",
      "AO" => "Angola")
      ?>


      Here is my Form-Collective "Select / Dropdown"




      Using Form Collective




         {{Form::select('country',  '', null, ['class' => 'form-control', 'placeholder' => 'Select Country...'])}}


      So how can i do it? Anyone who would like to help me, I appreciate it thank you!







      php arrays laravel drop-down-menu






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 23:21







      user10665294































          1 Answer
          1






          active

          oldest

          votes


















          0














          The second parameter in the Form collective select function receives an array of values that you want to be displayed, so simply pass your array, and change {{ with {!! which escapes the HTML output instead of printing it out as text.



             {!! Form::select('country',  $countries, null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}


          --- EDIT



          If you don't have an admin panel from which you enter a country, then the simplest way with which I will go is store the countries in a language file. For example:



          in resources/lang/en/countries.php



          return [
          "AF" => "Afghanistan",
          "AL" => "Albania",
          "DZ" => "Algeria",
          "AS" => "American Samoa",
          "AD" => "Andorra",
          "AO" => "Angola"
          ];


          then in your view:



          {!! Form::select('country',  trans('countries'), null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}





          share|improve this answer


























          • It does not work :( . I think there's something wrong or It needed to add something

            – user10665294
            Nov 16 '18 at 23:53











          • @SummerWinter How are you passing the array, or what error do you get? Have you tried inline if it will work, such as this {!! Form::select('country', ["AF" => "Afghanistan", "AL" => "Albania"], null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}

            – nakov
            Nov 16 '18 at 23:58













          • Yeah it work like that .. but im just wondering if there's a short way on how to generate or store the array like the simplest and practical way

            – user10665294
            Nov 17 '18 at 0:03











          • @SummerWinter Look at my edit.

            – nakov
            Nov 17 '18 at 0:14











          • It does work !! thank you for helping beginners like me

            – user10665294
            Nov 17 '18 at 6:39












          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%2f53346633%2flaravel-populate-drop-down-list-of-countries-using-form-collective-using-array%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














          The second parameter in the Form collective select function receives an array of values that you want to be displayed, so simply pass your array, and change {{ with {!! which escapes the HTML output instead of printing it out as text.



             {!! Form::select('country',  $countries, null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}


          --- EDIT



          If you don't have an admin panel from which you enter a country, then the simplest way with which I will go is store the countries in a language file. For example:



          in resources/lang/en/countries.php



          return [
          "AF" => "Afghanistan",
          "AL" => "Albania",
          "DZ" => "Algeria",
          "AS" => "American Samoa",
          "AD" => "Andorra",
          "AO" => "Angola"
          ];


          then in your view:



          {!! Form::select('country',  trans('countries'), null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}





          share|improve this answer


























          • It does not work :( . I think there's something wrong or It needed to add something

            – user10665294
            Nov 16 '18 at 23:53











          • @SummerWinter How are you passing the array, or what error do you get? Have you tried inline if it will work, such as this {!! Form::select('country', ["AF" => "Afghanistan", "AL" => "Albania"], null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}

            – nakov
            Nov 16 '18 at 23:58













          • Yeah it work like that .. but im just wondering if there's a short way on how to generate or store the array like the simplest and practical way

            – user10665294
            Nov 17 '18 at 0:03











          • @SummerWinter Look at my edit.

            – nakov
            Nov 17 '18 at 0:14











          • It does work !! thank you for helping beginners like me

            – user10665294
            Nov 17 '18 at 6:39
















          0














          The second parameter in the Form collective select function receives an array of values that you want to be displayed, so simply pass your array, and change {{ with {!! which escapes the HTML output instead of printing it out as text.



             {!! Form::select('country',  $countries, null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}


          --- EDIT



          If you don't have an admin panel from which you enter a country, then the simplest way with which I will go is store the countries in a language file. For example:



          in resources/lang/en/countries.php



          return [
          "AF" => "Afghanistan",
          "AL" => "Albania",
          "DZ" => "Algeria",
          "AS" => "American Samoa",
          "AD" => "Andorra",
          "AO" => "Angola"
          ];


          then in your view:



          {!! Form::select('country',  trans('countries'), null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}





          share|improve this answer


























          • It does not work :( . I think there's something wrong or It needed to add something

            – user10665294
            Nov 16 '18 at 23:53











          • @SummerWinter How are you passing the array, or what error do you get? Have you tried inline if it will work, such as this {!! Form::select('country', ["AF" => "Afghanistan", "AL" => "Albania"], null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}

            – nakov
            Nov 16 '18 at 23:58













          • Yeah it work like that .. but im just wondering if there's a short way on how to generate or store the array like the simplest and practical way

            – user10665294
            Nov 17 '18 at 0:03











          • @SummerWinter Look at my edit.

            – nakov
            Nov 17 '18 at 0:14











          • It does work !! thank you for helping beginners like me

            – user10665294
            Nov 17 '18 at 6:39














          0












          0








          0







          The second parameter in the Form collective select function receives an array of values that you want to be displayed, so simply pass your array, and change {{ with {!! which escapes the HTML output instead of printing it out as text.



             {!! Form::select('country',  $countries, null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}


          --- EDIT



          If you don't have an admin panel from which you enter a country, then the simplest way with which I will go is store the countries in a language file. For example:



          in resources/lang/en/countries.php



          return [
          "AF" => "Afghanistan",
          "AL" => "Albania",
          "DZ" => "Algeria",
          "AS" => "American Samoa",
          "AD" => "Andorra",
          "AO" => "Angola"
          ];


          then in your view:



          {!! Form::select('country',  trans('countries'), null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}





          share|improve this answer















          The second parameter in the Form collective select function receives an array of values that you want to be displayed, so simply pass your array, and change {{ with {!! which escapes the HTML output instead of printing it out as text.



             {!! Form::select('country',  $countries, null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}


          --- EDIT



          If you don't have an admin panel from which you enter a country, then the simplest way with which I will go is store the countries in a language file. For example:



          in resources/lang/en/countries.php



          return [
          "AF" => "Afghanistan",
          "AL" => "Albania",
          "DZ" => "Algeria",
          "AS" => "American Samoa",
          "AD" => "Andorra",
          "AO" => "Angola"
          ];


          then in your view:



          {!! Form::select('country',  trans('countries'), null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 17 '18 at 0:14

























          answered Nov 16 '18 at 23:39









          nakovnakov

          3,8012811




          3,8012811













          • It does not work :( . I think there's something wrong or It needed to add something

            – user10665294
            Nov 16 '18 at 23:53











          • @SummerWinter How are you passing the array, or what error do you get? Have you tried inline if it will work, such as this {!! Form::select('country', ["AF" => "Afghanistan", "AL" => "Albania"], null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}

            – nakov
            Nov 16 '18 at 23:58













          • Yeah it work like that .. but im just wondering if there's a short way on how to generate or store the array like the simplest and practical way

            – user10665294
            Nov 17 '18 at 0:03











          • @SummerWinter Look at my edit.

            – nakov
            Nov 17 '18 at 0:14











          • It does work !! thank you for helping beginners like me

            – user10665294
            Nov 17 '18 at 6:39



















          • It does not work :( . I think there's something wrong or It needed to add something

            – user10665294
            Nov 16 '18 at 23:53











          • @SummerWinter How are you passing the array, or what error do you get? Have you tried inline if it will work, such as this {!! Form::select('country', ["AF" => "Afghanistan", "AL" => "Albania"], null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}

            – nakov
            Nov 16 '18 at 23:58













          • Yeah it work like that .. but im just wondering if there's a short way on how to generate or store the array like the simplest and practical way

            – user10665294
            Nov 17 '18 at 0:03











          • @SummerWinter Look at my edit.

            – nakov
            Nov 17 '18 at 0:14











          • It does work !! thank you for helping beginners like me

            – user10665294
            Nov 17 '18 at 6:39

















          It does not work :( . I think there's something wrong or It needed to add something

          – user10665294
          Nov 16 '18 at 23:53





          It does not work :( . I think there's something wrong or It needed to add something

          – user10665294
          Nov 16 '18 at 23:53













          @SummerWinter How are you passing the array, or what error do you get? Have you tried inline if it will work, such as this {!! Form::select('country', ["AF" => "Afghanistan", "AL" => "Albania"], null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}

          – nakov
          Nov 16 '18 at 23:58







          @SummerWinter How are you passing the array, or what error do you get? Have you tried inline if it will work, such as this {!! Form::select('country', ["AF" => "Afghanistan", "AL" => "Albania"], null, ['class' => 'form-control', 'placeholder' => 'Select Country...']) !!}

          – nakov
          Nov 16 '18 at 23:58















          Yeah it work like that .. but im just wondering if there's a short way on how to generate or store the array like the simplest and practical way

          – user10665294
          Nov 17 '18 at 0:03





          Yeah it work like that .. but im just wondering if there's a short way on how to generate or store the array like the simplest and practical way

          – user10665294
          Nov 17 '18 at 0:03













          @SummerWinter Look at my edit.

          – nakov
          Nov 17 '18 at 0:14





          @SummerWinter Look at my edit.

          – nakov
          Nov 17 '18 at 0:14













          It does work !! thank you for helping beginners like me

          – user10665294
          Nov 17 '18 at 6:39





          It does work !! thank you for helping beginners like me

          – user10665294
          Nov 17 '18 at 6:39




















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346633%2flaravel-populate-drop-down-list-of-countries-using-form-collective-using-array%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







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine