How to pass a VueJS variable into a Laravel blade routeHow to place vue variable inside a laravel bracketReference - What does this error mean in PHP?How to Set Variables in a Laravel Blade TemplateHow to pass variables and data from PHP to JavaScript?Laravel navigation bar not working after using a route with $id parameter?laravel blade template variablesLaravel / Blade - is it possible to echo a variable into the parameter of a function?How to loop records through textfield valueLaravel blade, recursive view with php translated to bladeUsing JavaScript variables inside laravel blade routesSearch in vuejs with laravel backend api

C++ check if statement can be evaluated constexpr

Why do ¬, ∀ and ∃ have the same precedence?

How to make money from a browser who sees 5 seconds into the future of any web page?

Why do Radio Buttons not fill the entire outer circle?

When were female captains banned from Starfleet?

What kind of floor tile is this?

Why is so much work done on numerical verification of the Riemann Hypothesis?

How can I write humor as character trait?

What does Apple's new App Store requirement mean

Is there a RAID 0 Equivalent for RAM?

Does Doodling or Improvising on the Piano Have Any Benefits?

Taxes on Dividends in a Roth IRA

Stack Interview Code methods made from class Node and Smart Pointers

C++ copy constructor called at return

Change the color of a single dot in `ddot` symbol

Does "he squandered his car on drink" sound natural?

Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?

Creating two special characters

Is it allowed to activate the ability of multiple planeswalkers in a single turn?

How much of a Devil Fruit must be consumed to gain the power?

A variation to the phrase "hanging over my shoulders"

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

Is this part of the description of the Archfey warlock's Misty Escape feature redundant?

Has any country ever had 2 former presidents in jail simultaneously?



How to pass a VueJS variable into a Laravel blade route


How to place vue variable inside a laravel bracketReference - What does this error mean in PHP?How to Set Variables in a Laravel Blade TemplateHow to pass variables and data from PHP to JavaScript?Laravel navigation bar not working after using a route with $id parameter?laravel blade template variablesLaravel / Blade - is it possible to echo a variable into the parameter of a function?How to loop records through textfield valueLaravel blade, recursive view with php translated to bladeUsing JavaScript variables inside laravel blade routesSearch in vuejs with laravel backend api













3















I'm looping over a JSON array in VueJS and outputting each item to the screen but I need to create a link/route to a resource controller with the ID being returned for each row like so:



<tr v-for="item in searchResults.group">
<td>
<a href=" route('admin.edit', @ item.id ) "><button type="button" class="btn btn-info btn-sm">Edit</button></a>


So I've tried putting the variable into the route like so @ item.id but get the error:



syntax error, unexpected '{' (View: /application/resources/views/admin/edit.blade.php)



The way I have done it is not the correct way obviously but I can't find anything in the documentation to achieve this.




EDIT:



Further input on this. The route function requires a second parameter, in this case, the ID of the item to edit. In pure PHP/Blade I have this and it works:



<a href=" route('admin.edit', $item->id ) "><button type="button" class="btn btn-info btn-sm">Reduce</button></a>


For the dynamic search page, I need to somehow pass that second parameter into blade/php from a vuejs variable but I just can't work out how to do it.










share|improve this question
























  • Can you show route defined in web file?

    – Saad Suri
    13 hours ago











  • Possible duplicate of How to place vue variable inside a laravel bracket

    – Emīls Gulbis
    13 hours ago















3















I'm looping over a JSON array in VueJS and outputting each item to the screen but I need to create a link/route to a resource controller with the ID being returned for each row like so:



<tr v-for="item in searchResults.group">
<td>
<a href=" route('admin.edit', @ item.id ) "><button type="button" class="btn btn-info btn-sm">Edit</button></a>


So I've tried putting the variable into the route like so @ item.id but get the error:



syntax error, unexpected '{' (View: /application/resources/views/admin/edit.blade.php)



The way I have done it is not the correct way obviously but I can't find anything in the documentation to achieve this.




EDIT:



Further input on this. The route function requires a second parameter, in this case, the ID of the item to edit. In pure PHP/Blade I have this and it works:



<a href=" route('admin.edit', $item->id ) "><button type="button" class="btn btn-info btn-sm">Reduce</button></a>


For the dynamic search page, I need to somehow pass that second parameter into blade/php from a vuejs variable but I just can't work out how to do it.










share|improve this question
























  • Can you show route defined in web file?

    – Saad Suri
    13 hours ago











  • Possible duplicate of How to place vue variable inside a laravel bracket

    – Emīls Gulbis
    13 hours ago













3












3








3








I'm looping over a JSON array in VueJS and outputting each item to the screen but I need to create a link/route to a resource controller with the ID being returned for each row like so:



<tr v-for="item in searchResults.group">
<td>
<a href=" route('admin.edit', @ item.id ) "><button type="button" class="btn btn-info btn-sm">Edit</button></a>


So I've tried putting the variable into the route like so @ item.id but get the error:



syntax error, unexpected '{' (View: /application/resources/views/admin/edit.blade.php)



The way I have done it is not the correct way obviously but I can't find anything in the documentation to achieve this.




EDIT:



Further input on this. The route function requires a second parameter, in this case, the ID of the item to edit. In pure PHP/Blade I have this and it works:



<a href=" route('admin.edit', $item->id ) "><button type="button" class="btn btn-info btn-sm">Reduce</button></a>


For the dynamic search page, I need to somehow pass that second parameter into blade/php from a vuejs variable but I just can't work out how to do it.










share|improve this question
















I'm looping over a JSON array in VueJS and outputting each item to the screen but I need to create a link/route to a resource controller with the ID being returned for each row like so:



<tr v-for="item in searchResults.group">
<td>
<a href=" route('admin.edit', @ item.id ) "><button type="button" class="btn btn-info btn-sm">Edit</button></a>


So I've tried putting the variable into the route like so @ item.id but get the error:



syntax error, unexpected '{' (View: /application/resources/views/admin/edit.blade.php)



The way I have done it is not the correct way obviously but I can't find anything in the documentation to achieve this.




EDIT:



Further input on this. The route function requires a second parameter, in this case, the ID of the item to edit. In pure PHP/Blade I have this and it works:



<a href=" route('admin.edit', $item->id ) "><button type="button" class="btn btn-info btn-sm">Reduce</button></a>


For the dynamic search page, I need to somehow pass that second parameter into blade/php from a vuejs variable but I just can't work out how to do it.







php laravel vue.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 13 hours ago







twigg

















asked 13 hours ago









twiggtwigg

1,28552961




1,28552961












  • Can you show route defined in web file?

    – Saad Suri
    13 hours ago











  • Possible duplicate of How to place vue variable inside a laravel bracket

    – Emīls Gulbis
    13 hours ago

















  • Can you show route defined in web file?

    – Saad Suri
    13 hours ago











  • Possible duplicate of How to place vue variable inside a laravel bracket

    – Emīls Gulbis
    13 hours ago
















Can you show route defined in web file?

– Saad Suri
13 hours ago





Can you show route defined in web file?

– Saad Suri
13 hours ago













Possible duplicate of How to place vue variable inside a laravel bracket

– Emīls Gulbis
13 hours ago





Possible duplicate of How to place vue variable inside a laravel bracket

– Emīls Gulbis
13 hours ago












3 Answers
3






active

oldest

votes


















0














You can try by appending the id to the end like so:



 route('admin.edit') /@ item.id 


I'm guessing you are following a REST URI guides so that would work for you.






share|improve this answer























  • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

    – twigg
    13 hours ago






  • 1





    @twigg What you could do was to define the route admin.edits parameter optional and then use the method I suggested in my answer. Not the best option but it's the only answer I'm seeing now. Let me know if you need more clarification and I can edit my answer

    – The dude
    12 hours ago


















0














Use Like this



 <a href=" route('admin.edit') ?course_id=@ item.id ">Click</a>





share|improve this answer










New contributor




Future Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

    – twigg
    13 hours ago


















0














You are mixing two concepts that won't go together like this.



The blade template is rendered server-side, whereas the parts of your vue.js related markup will be parsed on the client side (e.g. "browser").



Because of that, referencing a property of item within a blade expression will fail (as it does).



<a href=" route('admin.edit', @ item.id ) "



route(...) refers to an expression that is related to blade, an item is supposed to be a part of your vue.js app.



What you need to do is to dynamically create the link for editing the ressource within your vue.js app once you loop your searchResult.group.



You could achieve this by injecting a "route-template" for editing the ressource into your vue.js app and bind the href property to a vue.js method, like this:



<tr v-for="item in searchResults.group">
<a v-bind:href="getEditLink(item.id)">Edit</a>
....


The according method getEditLink(id) then assembles the actual link based on the given id of item and the provided "route"-template.






share|improve this answer








New contributor




mynd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















    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%2f55280055%2fhow-to-pass-a-vuejs-variable-into-a-laravel-blade-route%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 try by appending the id to the end like so:



     route('admin.edit') /@ item.id 


    I'm guessing you are following a REST URI guides so that would work for you.






    share|improve this answer























    • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

      – twigg
      13 hours ago






    • 1





      @twigg What you could do was to define the route admin.edits parameter optional and then use the method I suggested in my answer. Not the best option but it's the only answer I'm seeing now. Let me know if you need more clarification and I can edit my answer

      – The dude
      12 hours ago















    0














    You can try by appending the id to the end like so:



     route('admin.edit') /@ item.id 


    I'm guessing you are following a REST URI guides so that would work for you.






    share|improve this answer























    • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

      – twigg
      13 hours ago






    • 1





      @twigg What you could do was to define the route admin.edits parameter optional and then use the method I suggested in my answer. Not the best option but it's the only answer I'm seeing now. Let me know if you need more clarification and I can edit my answer

      – The dude
      12 hours ago













    0












    0








    0







    You can try by appending the id to the end like so:



     route('admin.edit') /@ item.id 


    I'm guessing you are following a REST URI guides so that would work for you.






    share|improve this answer













    You can try by appending the id to the end like so:



     route('admin.edit') /@ item.id 


    I'm guessing you are following a REST URI guides so that would work for you.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 13 hours ago









    The dudeThe dude

    4831616




    4831616












    • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

      – twigg
      13 hours ago






    • 1





      @twigg What you could do was to define the route admin.edits parameter optional and then use the method I suggested in my answer. Not the best option but it's the only answer I'm seeing now. Let me know if you need more clarification and I can edit my answer

      – The dude
      12 hours ago

















    • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

      – twigg
      13 hours ago






    • 1





      @twigg What you could do was to define the route admin.edits parameter optional and then use the method I suggested in my answer. Not the best option but it's the only answer I'm seeing now. Let me know if you need more clarification and I can edit my answer

      – The dude
      12 hours ago
















    Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

    – twigg
    13 hours ago





    Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

    – twigg
    13 hours ago




    1




    1





    @twigg What you could do was to define the route admin.edits parameter optional and then use the method I suggested in my answer. Not the best option but it's the only answer I'm seeing now. Let me know if you need more clarification and I can edit my answer

    – The dude
    12 hours ago





    @twigg What you could do was to define the route admin.edits parameter optional and then use the method I suggested in my answer. Not the best option but it's the only answer I'm seeing now. Let me know if you need more clarification and I can edit my answer

    – The dude
    12 hours ago













    0














    Use Like this



     <a href=" route('admin.edit') ?course_id=@ item.id ">Click</a>





    share|improve this answer










    New contributor




    Future Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















    • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

      – twigg
      13 hours ago















    0














    Use Like this



     <a href=" route('admin.edit') ?course_id=@ item.id ">Click</a>





    share|improve this answer










    New contributor




    Future Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















    • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

      – twigg
      13 hours ago













    0












    0








    0







    Use Like this



     <a href=" route('admin.edit') ?course_id=@ item.id ">Click</a>





    share|improve this answer










    New contributor




    Future Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.










    Use Like this



     <a href=" route('admin.edit') ?course_id=@ item.id ">Click</a>






    share|improve this answer










    New contributor




    Future Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.









    share|improve this answer



    share|improve this answer








    edited 13 hours ago





















    New contributor




    Future Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.









    answered 13 hours ago









    Future CoderFuture Coder

    1465




    1465




    New contributor




    Future Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





    New contributor





    Future Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    Future Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.












    • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

      – twigg
      13 hours ago

















    • Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

      – twigg
      13 hours ago
















    Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

    – twigg
    13 hours ago





    Hey thanks for the input, this doesn't work I tried something similar, it fails because route is expecting a second parameter (the id in this case) Missing required parameters for [Route: admin.edit] [URI: admin/edit/id]

    – twigg
    13 hours ago











    0














    You are mixing two concepts that won't go together like this.



    The blade template is rendered server-side, whereas the parts of your vue.js related markup will be parsed on the client side (e.g. "browser").



    Because of that, referencing a property of item within a blade expression will fail (as it does).



    <a href=" route('admin.edit', @ item.id ) "



    route(...) refers to an expression that is related to blade, an item is supposed to be a part of your vue.js app.



    What you need to do is to dynamically create the link for editing the ressource within your vue.js app once you loop your searchResult.group.



    You could achieve this by injecting a "route-template" for editing the ressource into your vue.js app and bind the href property to a vue.js method, like this:



    <tr v-for="item in searchResults.group">
    <a v-bind:href="getEditLink(item.id)">Edit</a>
    ....


    The according method getEditLink(id) then assembles the actual link based on the given id of item and the provided "route"-template.






    share|improve this answer








    New contributor




    mynd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0














      You are mixing two concepts that won't go together like this.



      The blade template is rendered server-side, whereas the parts of your vue.js related markup will be parsed on the client side (e.g. "browser").



      Because of that, referencing a property of item within a blade expression will fail (as it does).



      <a href=" route('admin.edit', @ item.id ) "



      route(...) refers to an expression that is related to blade, an item is supposed to be a part of your vue.js app.



      What you need to do is to dynamically create the link for editing the ressource within your vue.js app once you loop your searchResult.group.



      You could achieve this by injecting a "route-template" for editing the ressource into your vue.js app and bind the href property to a vue.js method, like this:



      <tr v-for="item in searchResults.group">
      <a v-bind:href="getEditLink(item.id)">Edit</a>
      ....


      The according method getEditLink(id) then assembles the actual link based on the given id of item and the provided "route"-template.






      share|improve this answer








      New contributor




      mynd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        0












        0








        0







        You are mixing two concepts that won't go together like this.



        The blade template is rendered server-side, whereas the parts of your vue.js related markup will be parsed on the client side (e.g. "browser").



        Because of that, referencing a property of item within a blade expression will fail (as it does).



        <a href=" route('admin.edit', @ item.id ) "



        route(...) refers to an expression that is related to blade, an item is supposed to be a part of your vue.js app.



        What you need to do is to dynamically create the link for editing the ressource within your vue.js app once you loop your searchResult.group.



        You could achieve this by injecting a "route-template" for editing the ressource into your vue.js app and bind the href property to a vue.js method, like this:



        <tr v-for="item in searchResults.group">
        <a v-bind:href="getEditLink(item.id)">Edit</a>
        ....


        The according method getEditLink(id) then assembles the actual link based on the given id of item and the provided "route"-template.






        share|improve this answer








        New contributor




        mynd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        You are mixing two concepts that won't go together like this.



        The blade template is rendered server-side, whereas the parts of your vue.js related markup will be parsed on the client side (e.g. "browser").



        Because of that, referencing a property of item within a blade expression will fail (as it does).



        <a href=" route('admin.edit', @ item.id ) "



        route(...) refers to an expression that is related to blade, an item is supposed to be a part of your vue.js app.



        What you need to do is to dynamically create the link for editing the ressource within your vue.js app once you loop your searchResult.group.



        You could achieve this by injecting a "route-template" for editing the ressource into your vue.js app and bind the href property to a vue.js method, like this:



        <tr v-for="item in searchResults.group">
        <a v-bind:href="getEditLink(item.id)">Edit</a>
        ....


        The according method getEditLink(id) then assembles the actual link based on the given id of item and the provided "route"-template.







        share|improve this answer








        New contributor




        mynd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        mynd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 11 hours ago









        myndmynd

        1164




        1164




        New contributor




        mynd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        mynd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        mynd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.



























            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%2f55280055%2fhow-to-pass-a-vuejs-variable-into-a-laravel-blade-route%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript