Laravel Store/Insert Array Values to Database Mysql












0















my problem here in my code is I cannot store or insert array values in Database MySQL, here is my controller code please help me. thank you. My Code in Controller has no array or any so.. I dont have any clue how to turn it into array.



Controller



    public function store(Request $request)
{
$this->validate($request,[
'city' => 'required'

]);


$citi = new City;
$citi->city = $request->input('city');
$citi->save();

return redirect('/lugar')->with('success', 'Data Inserted');
}


View



<td> {{Form::text('city', '', ['class' => 'form-control name_list', 'placeholder' => 'Add Country'])}} </td>









share|improve this question


















  • 1





    What errors are you getting?

    – Peter Sowah
    Nov 24 '18 at 22:52











  • here, see _Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given _

    – user10665294
    Nov 24 '18 at 22:54













  • Possible duplicate of Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given

    – George Udosen
    Nov 24 '18 at 23:01











  • it is not laravel it is pure php. i dont understand :(

    – user10665294
    Nov 24 '18 at 23:17
















0















my problem here in my code is I cannot store or insert array values in Database MySQL, here is my controller code please help me. thank you. My Code in Controller has no array or any so.. I dont have any clue how to turn it into array.



Controller



    public function store(Request $request)
{
$this->validate($request,[
'city' => 'required'

]);


$citi = new City;
$citi->city = $request->input('city');
$citi->save();

return redirect('/lugar')->with('success', 'Data Inserted');
}


View



<td> {{Form::text('city', '', ['class' => 'form-control name_list', 'placeholder' => 'Add Country'])}} </td>









share|improve this question


















  • 1





    What errors are you getting?

    – Peter Sowah
    Nov 24 '18 at 22:52











  • here, see _Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given _

    – user10665294
    Nov 24 '18 at 22:54













  • Possible duplicate of Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given

    – George Udosen
    Nov 24 '18 at 23:01











  • it is not laravel it is pure php. i dont understand :(

    – user10665294
    Nov 24 '18 at 23:17














0












0








0








my problem here in my code is I cannot store or insert array values in Database MySQL, here is my controller code please help me. thank you. My Code in Controller has no array or any so.. I dont have any clue how to turn it into array.



Controller



    public function store(Request $request)
{
$this->validate($request,[
'city' => 'required'

]);


$citi = new City;
$citi->city = $request->input('city');
$citi->save();

return redirect('/lugar')->with('success', 'Data Inserted');
}


View



<td> {{Form::text('city', '', ['class' => 'form-control name_list', 'placeholder' => 'Add Country'])}} </td>









share|improve this question














my problem here in my code is I cannot store or insert array values in Database MySQL, here is my controller code please help me. thank you. My Code in Controller has no array or any so.. I dont have any clue how to turn it into array.



Controller



    public function store(Request $request)
{
$this->validate($request,[
'city' => 'required'

]);


$citi = new City;
$citi->city = $request->input('city');
$citi->save();

return redirect('/lugar')->with('success', 'Data Inserted');
}


View



<td> {{Form::text('city', '', ['class' => 'form-control name_list', 'placeholder' => 'Add Country'])}} </td>






php mysql arrays laravel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 22:48







user10665294















  • 1





    What errors are you getting?

    – Peter Sowah
    Nov 24 '18 at 22:52











  • here, see _Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given _

    – user10665294
    Nov 24 '18 at 22:54













  • Possible duplicate of Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given

    – George Udosen
    Nov 24 '18 at 23:01











  • it is not laravel it is pure php. i dont understand :(

    – user10665294
    Nov 24 '18 at 23:17














  • 1





    What errors are you getting?

    – Peter Sowah
    Nov 24 '18 at 22:52











  • here, see _Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given _

    – user10665294
    Nov 24 '18 at 22:54













  • Possible duplicate of Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given

    – George Udosen
    Nov 24 '18 at 23:01











  • it is not laravel it is pure php. i dont understand :(

    – user10665294
    Nov 24 '18 at 23:17








1




1





What errors are you getting?

– Peter Sowah
Nov 24 '18 at 22:52





What errors are you getting?

– Peter Sowah
Nov 24 '18 at 22:52













here, see _Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given _

– user10665294
Nov 24 '18 at 22:54







here, see _Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given _

– user10665294
Nov 24 '18 at 22:54















Possible duplicate of Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given

– George Udosen
Nov 24 '18 at 23:01





Possible duplicate of Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given

– George Udosen
Nov 24 '18 at 23:01













it is not laravel it is pure php. i dont understand :(

– user10665294
Nov 24 '18 at 23:17





it is not laravel it is pure php. i dont understand :(

– user10665294
Nov 24 '18 at 23:17












3 Answers
3






active

oldest

votes


















0














You can't store arrays in MySQL, its different if you compared it with Mongo (NoSQL).



What you can do is, turn that array into a json string. So json_encode($request->city) and save it.



Then if you want to modify it's values once retrieved from DB, you can use json_decode($data->city) which turns it back to an array.






share|improve this answer































    0














    you can actually save this using serialize or json_encode.



    Using serialize:



    $citi->city = serialize($request->input('city'));


    Using json_encode:



    $citi->city = json_encode($request->input('city'));


    then just use unserialize and json_decode on your blade file.






    share|improve this answer
























    • how can I unserialized it??

      – user10665294
      Nov 25 '18 at 1:23











    • Arrays are now in my database but they are serialized.. how can I unserialized them? they have the value of this a:2:{i:0;s:7:"New York";i:1;s:8:"Chicago";}

      – user10665294
      Nov 25 '18 at 1:25











    • hey @kapitan, all works fine except for the a:2:{i:0;s:7: for this serial code.. can i remove that and change it to normal? help me so i can upvote your answer and marked it as an asnwer ty

      – user10665294
      Nov 25 '18 at 1:34











    • Check my answer, it shows you both ways

      – Adis
      Nov 25 '18 at 1:36











    • unserialize($myvariable) or json_decode($myvariable)

      – kapitan
      Nov 26 '18 at 1:55



















    -1














    You can use serialize() or i think json_encode() to stringify the array.
    There is another theme where similar problem has been discussed.



    here






    share|improve this answer
























    • can you edit my code? see im new to coding in laravel and never used serializing or json_encoding

      – user10665294
      Nov 24 '18 at 22:53











    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%2f53463025%2flaravel-store-insert-array-values-to-database-mysql%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown
























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can't store arrays in MySQL, its different if you compared it with Mongo (NoSQL).



    What you can do is, turn that array into a json string. So json_encode($request->city) and save it.



    Then if you want to modify it's values once retrieved from DB, you can use json_decode($data->city) which turns it back to an array.






    share|improve this answer




























      0














      You can't store arrays in MySQL, its different if you compared it with Mongo (NoSQL).



      What you can do is, turn that array into a json string. So json_encode($request->city) and save it.



      Then if you want to modify it's values once retrieved from DB, you can use json_decode($data->city) which turns it back to an array.






      share|improve this answer


























        0












        0








        0







        You can't store arrays in MySQL, its different if you compared it with Mongo (NoSQL).



        What you can do is, turn that array into a json string. So json_encode($request->city) and save it.



        Then if you want to modify it's values once retrieved from DB, you can use json_decode($data->city) which turns it back to an array.






        share|improve this answer













        You can't store arrays in MySQL, its different if you compared it with Mongo (NoSQL).



        What you can do is, turn that array into a json string. So json_encode($request->city) and save it.



        Then if you want to modify it's values once retrieved from DB, you can use json_decode($data->city) which turns it back to an array.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 0:52









        AdisAdis

        413317




        413317

























            0














            you can actually save this using serialize or json_encode.



            Using serialize:



            $citi->city = serialize($request->input('city'));


            Using json_encode:



            $citi->city = json_encode($request->input('city'));


            then just use unserialize and json_decode on your blade file.






            share|improve this answer
























            • how can I unserialized it??

              – user10665294
              Nov 25 '18 at 1:23











            • Arrays are now in my database but they are serialized.. how can I unserialized them? they have the value of this a:2:{i:0;s:7:"New York";i:1;s:8:"Chicago";}

              – user10665294
              Nov 25 '18 at 1:25











            • hey @kapitan, all works fine except for the a:2:{i:0;s:7: for this serial code.. can i remove that and change it to normal? help me so i can upvote your answer and marked it as an asnwer ty

              – user10665294
              Nov 25 '18 at 1:34











            • Check my answer, it shows you both ways

              – Adis
              Nov 25 '18 at 1:36











            • unserialize($myvariable) or json_decode($myvariable)

              – kapitan
              Nov 26 '18 at 1:55
















            0














            you can actually save this using serialize or json_encode.



            Using serialize:



            $citi->city = serialize($request->input('city'));


            Using json_encode:



            $citi->city = json_encode($request->input('city'));


            then just use unserialize and json_decode on your blade file.






            share|improve this answer
























            • how can I unserialized it??

              – user10665294
              Nov 25 '18 at 1:23











            • Arrays are now in my database but they are serialized.. how can I unserialized them? they have the value of this a:2:{i:0;s:7:"New York";i:1;s:8:"Chicago";}

              – user10665294
              Nov 25 '18 at 1:25











            • hey @kapitan, all works fine except for the a:2:{i:0;s:7: for this serial code.. can i remove that and change it to normal? help me so i can upvote your answer and marked it as an asnwer ty

              – user10665294
              Nov 25 '18 at 1:34











            • Check my answer, it shows you both ways

              – Adis
              Nov 25 '18 at 1:36











            • unserialize($myvariable) or json_decode($myvariable)

              – kapitan
              Nov 26 '18 at 1:55














            0












            0








            0







            you can actually save this using serialize or json_encode.



            Using serialize:



            $citi->city = serialize($request->input('city'));


            Using json_encode:



            $citi->city = json_encode($request->input('city'));


            then just use unserialize and json_decode on your blade file.






            share|improve this answer













            you can actually save this using serialize or json_encode.



            Using serialize:



            $citi->city = serialize($request->input('city'));


            Using json_encode:



            $citi->city = json_encode($request->input('city'));


            then just use unserialize and json_decode on your blade file.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 25 '18 at 1:16









            kapitankapitan

            570210




            570210













            • how can I unserialized it??

              – user10665294
              Nov 25 '18 at 1:23











            • Arrays are now in my database but they are serialized.. how can I unserialized them? they have the value of this a:2:{i:0;s:7:"New York";i:1;s:8:"Chicago";}

              – user10665294
              Nov 25 '18 at 1:25











            • hey @kapitan, all works fine except for the a:2:{i:0;s:7: for this serial code.. can i remove that and change it to normal? help me so i can upvote your answer and marked it as an asnwer ty

              – user10665294
              Nov 25 '18 at 1:34











            • Check my answer, it shows you both ways

              – Adis
              Nov 25 '18 at 1:36











            • unserialize($myvariable) or json_decode($myvariable)

              – kapitan
              Nov 26 '18 at 1:55



















            • how can I unserialized it??

              – user10665294
              Nov 25 '18 at 1:23











            • Arrays are now in my database but they are serialized.. how can I unserialized them? they have the value of this a:2:{i:0;s:7:"New York";i:1;s:8:"Chicago";}

              – user10665294
              Nov 25 '18 at 1:25











            • hey @kapitan, all works fine except for the a:2:{i:0;s:7: for this serial code.. can i remove that and change it to normal? help me so i can upvote your answer and marked it as an asnwer ty

              – user10665294
              Nov 25 '18 at 1:34











            • Check my answer, it shows you both ways

              – Adis
              Nov 25 '18 at 1:36











            • unserialize($myvariable) or json_decode($myvariable)

              – kapitan
              Nov 26 '18 at 1:55

















            how can I unserialized it??

            – user10665294
            Nov 25 '18 at 1:23





            how can I unserialized it??

            – user10665294
            Nov 25 '18 at 1:23













            Arrays are now in my database but they are serialized.. how can I unserialized them? they have the value of this a:2:{i:0;s:7:"New York";i:1;s:8:"Chicago";}

            – user10665294
            Nov 25 '18 at 1:25





            Arrays are now in my database but they are serialized.. how can I unserialized them? they have the value of this a:2:{i:0;s:7:"New York";i:1;s:8:"Chicago";}

            – user10665294
            Nov 25 '18 at 1:25













            hey @kapitan, all works fine except for the a:2:{i:0;s:7: for this serial code.. can i remove that and change it to normal? help me so i can upvote your answer and marked it as an asnwer ty

            – user10665294
            Nov 25 '18 at 1:34





            hey @kapitan, all works fine except for the a:2:{i:0;s:7: for this serial code.. can i remove that and change it to normal? help me so i can upvote your answer and marked it as an asnwer ty

            – user10665294
            Nov 25 '18 at 1:34













            Check my answer, it shows you both ways

            – Adis
            Nov 25 '18 at 1:36





            Check my answer, it shows you both ways

            – Adis
            Nov 25 '18 at 1:36













            unserialize($myvariable) or json_decode($myvariable)

            – kapitan
            Nov 26 '18 at 1:55





            unserialize($myvariable) or json_decode($myvariable)

            – kapitan
            Nov 26 '18 at 1:55











            -1














            You can use serialize() or i think json_encode() to stringify the array.
            There is another theme where similar problem has been discussed.



            here






            share|improve this answer
























            • can you edit my code? see im new to coding in laravel and never used serializing or json_encoding

              – user10665294
              Nov 24 '18 at 22:53
















            -1














            You can use serialize() or i think json_encode() to stringify the array.
            There is another theme where similar problem has been discussed.



            here






            share|improve this answer
























            • can you edit my code? see im new to coding in laravel and never used serializing or json_encoding

              – user10665294
              Nov 24 '18 at 22:53














            -1












            -1








            -1







            You can use serialize() or i think json_encode() to stringify the array.
            There is another theme where similar problem has been discussed.



            here






            share|improve this answer













            You can use serialize() or i think json_encode() to stringify the array.
            There is another theme where similar problem has been discussed.



            here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 24 '18 at 22:52









            Martin KiriloffMartin Kiriloff

            12




            12













            • can you edit my code? see im new to coding in laravel and never used serializing or json_encoding

              – user10665294
              Nov 24 '18 at 22:53



















            • can you edit my code? see im new to coding in laravel and never used serializing or json_encoding

              – user10665294
              Nov 24 '18 at 22:53

















            can you edit my code? see im new to coding in laravel and never used serializing or json_encoding

            – user10665294
            Nov 24 '18 at 22:53





            can you edit my code? see im new to coding in laravel and never used serializing or json_encoding

            – user10665294
            Nov 24 '18 at 22:53


















            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%2f53463025%2flaravel-store-insert-array-values-to-database-mysql%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

            Costa Masnaga

            Fotorealismo

            Sidney Franklin