Call to undefined function, changes on helper.php file but still cant call presentPrice function












0















in my view file I try to add this code, but cant call the function name 'present price'



<table>
<tr>
<td>RM {{presentPrice(session()->get('coupon')['name'])}}</td>
</tr>
</table>


this function I add it into the app/helper path



<?php
class helpers{
function presentPrice($price)
{
return money_format('$%i', $price / 100);
}
}


of course I have to run composer dump-autoload. But it still show me undefined function










share|improve this question























  • Have you defined Helper Class

    – Gaurav Rai
    Nov 13 '18 at 8:55











  • may I know where to defined it? Because I think view file can't defined 'use helper' ?

    – lun7code
    Nov 13 '18 at 8:56











  • answered please go through it.

    – Gaurav Rai
    Nov 13 '18 at 9:14
















0















in my view file I try to add this code, but cant call the function name 'present price'



<table>
<tr>
<td>RM {{presentPrice(session()->get('coupon')['name'])}}</td>
</tr>
</table>


this function I add it into the app/helper path



<?php
class helpers{
function presentPrice($price)
{
return money_format('$%i', $price / 100);
}
}


of course I have to run composer dump-autoload. But it still show me undefined function










share|improve this question























  • Have you defined Helper Class

    – Gaurav Rai
    Nov 13 '18 at 8:55











  • may I know where to defined it? Because I think view file can't defined 'use helper' ?

    – lun7code
    Nov 13 '18 at 8:56











  • answered please go through it.

    – Gaurav Rai
    Nov 13 '18 at 9:14














0












0








0








in my view file I try to add this code, but cant call the function name 'present price'



<table>
<tr>
<td>RM {{presentPrice(session()->get('coupon')['name'])}}</td>
</tr>
</table>


this function I add it into the app/helper path



<?php
class helpers{
function presentPrice($price)
{
return money_format('$%i', $price / 100);
}
}


of course I have to run composer dump-autoload. But it still show me undefined function










share|improve this question














in my view file I try to add this code, but cant call the function name 'present price'



<table>
<tr>
<td>RM {{presentPrice(session()->get('coupon')['name'])}}</td>
</tr>
</table>


this function I add it into the app/helper path



<?php
class helpers{
function presentPrice($price)
{
return money_format('$%i', $price / 100);
}
}


of course I have to run composer dump-autoload. But it still show me undefined function







php laravel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 8:51









lun7codelun7code

548




548













  • Have you defined Helper Class

    – Gaurav Rai
    Nov 13 '18 at 8:55











  • may I know where to defined it? Because I think view file can't defined 'use helper' ?

    – lun7code
    Nov 13 '18 at 8:56











  • answered please go through it.

    – Gaurav Rai
    Nov 13 '18 at 9:14



















  • Have you defined Helper Class

    – Gaurav Rai
    Nov 13 '18 at 8:55











  • may I know where to defined it? Because I think view file can't defined 'use helper' ?

    – lun7code
    Nov 13 '18 at 8:56











  • answered please go through it.

    – Gaurav Rai
    Nov 13 '18 at 9:14

















Have you defined Helper Class

– Gaurav Rai
Nov 13 '18 at 8:55





Have you defined Helper Class

– Gaurav Rai
Nov 13 '18 at 8:55













may I know where to defined it? Because I think view file can't defined 'use helper' ?

– lun7code
Nov 13 '18 at 8:56





may I know where to defined it? Because I think view file can't defined 'use helper' ?

– lun7code
Nov 13 '18 at 8:56













answered please go through it.

– Gaurav Rai
Nov 13 '18 at 9:14





answered please go through it.

– Gaurav Rai
Nov 13 '18 at 9:14












2 Answers
2






active

oldest

votes


















0














You have put it inside a class . If you want to define helper functions you should:



Change your helpers source to:



<?php
function presentPrice($price) {
return money_format('$%i', $price / 100);
}


Then add this to your composer.json



"autoload": {
"files": [
"app/helper.php"
],
keep the rest of the autoload parts as is
}


Then run composer dump-autoload again. This should make the file app/helper.php load automatically every time. (If the file is in a different path then update accordingly)



This will make presentPrice() available everywhere.






share|improve this answer































    0














    Create your Helper file




    /app/Helpers/Helper.php




    <?php 

    namespace AppHelpers;
    class Helper{
    public static function MoneyFormat($number){}
    }



    /config/app.php




    define alias



    'Helper' => AppHelpersHelper::class,



    /app/Http/Controllers/YourController.php




    use Helper;


    and use it where ever you want like



    Helper::MoneyFormat($price)





    share|improve this answer


























    • it show the error undefined class error when i define alias.

      – lun7code
      Nov 13 '18 at 9:24











    • Have you created helper file /app/Helpers/Helper.php updated my answer

      – Gaurav Rai
      Nov 13 '18 at 9:26













    • my path is here ---> app/helpers.php

      – lun7code
      Nov 13 '18 at 9:30











    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%2f53277094%2fcall-to-undefined-function-changes-on-helper-php-file-but-still-cant-call-prese%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You have put it inside a class . If you want to define helper functions you should:



    Change your helpers source to:



    <?php
    function presentPrice($price) {
    return money_format('$%i', $price / 100);
    }


    Then add this to your composer.json



    "autoload": {
    "files": [
    "app/helper.php"
    ],
    keep the rest of the autoload parts as is
    }


    Then run composer dump-autoload again. This should make the file app/helper.php load automatically every time. (If the file is in a different path then update accordingly)



    This will make presentPrice() available everywhere.






    share|improve this answer




























      0














      You have put it inside a class . If you want to define helper functions you should:



      Change your helpers source to:



      <?php
      function presentPrice($price) {
      return money_format('$%i', $price / 100);
      }


      Then add this to your composer.json



      "autoload": {
      "files": [
      "app/helper.php"
      ],
      keep the rest of the autoload parts as is
      }


      Then run composer dump-autoload again. This should make the file app/helper.php load automatically every time. (If the file is in a different path then update accordingly)



      This will make presentPrice() available everywhere.






      share|improve this answer


























        0












        0








        0







        You have put it inside a class . If you want to define helper functions you should:



        Change your helpers source to:



        <?php
        function presentPrice($price) {
        return money_format('$%i', $price / 100);
        }


        Then add this to your composer.json



        "autoload": {
        "files": [
        "app/helper.php"
        ],
        keep the rest of the autoload parts as is
        }


        Then run composer dump-autoload again. This should make the file app/helper.php load automatically every time. (If the file is in a different path then update accordingly)



        This will make presentPrice() available everywhere.






        share|improve this answer













        You have put it inside a class . If you want to define helper functions you should:



        Change your helpers source to:



        <?php
        function presentPrice($price) {
        return money_format('$%i', $price / 100);
        }


        Then add this to your composer.json



        "autoload": {
        "files": [
        "app/helper.php"
        ],
        keep the rest of the autoload parts as is
        }


        Then run composer dump-autoload again. This should make the file app/helper.php load automatically every time. (If the file is in a different path then update accordingly)



        This will make presentPrice() available everywhere.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 8:57









        apokryfosapokryfos

        18.3k42956




        18.3k42956

























            0














            Create your Helper file




            /app/Helpers/Helper.php




            <?php 

            namespace AppHelpers;
            class Helper{
            public static function MoneyFormat($number){}
            }



            /config/app.php




            define alias



            'Helper' => AppHelpersHelper::class,



            /app/Http/Controllers/YourController.php




            use Helper;


            and use it where ever you want like



            Helper::MoneyFormat($price)





            share|improve this answer


























            • it show the error undefined class error when i define alias.

              – lun7code
              Nov 13 '18 at 9:24











            • Have you created helper file /app/Helpers/Helper.php updated my answer

              – Gaurav Rai
              Nov 13 '18 at 9:26













            • my path is here ---> app/helpers.php

              – lun7code
              Nov 13 '18 at 9:30
















            0














            Create your Helper file




            /app/Helpers/Helper.php




            <?php 

            namespace AppHelpers;
            class Helper{
            public static function MoneyFormat($number){}
            }



            /config/app.php




            define alias



            'Helper' => AppHelpersHelper::class,



            /app/Http/Controllers/YourController.php




            use Helper;


            and use it where ever you want like



            Helper::MoneyFormat($price)





            share|improve this answer


























            • it show the error undefined class error when i define alias.

              – lun7code
              Nov 13 '18 at 9:24











            • Have you created helper file /app/Helpers/Helper.php updated my answer

              – Gaurav Rai
              Nov 13 '18 at 9:26













            • my path is here ---> app/helpers.php

              – lun7code
              Nov 13 '18 at 9:30














            0












            0








            0







            Create your Helper file




            /app/Helpers/Helper.php




            <?php 

            namespace AppHelpers;
            class Helper{
            public static function MoneyFormat($number){}
            }



            /config/app.php




            define alias



            'Helper' => AppHelpersHelper::class,



            /app/Http/Controllers/YourController.php




            use Helper;


            and use it where ever you want like



            Helper::MoneyFormat($price)





            share|improve this answer















            Create your Helper file




            /app/Helpers/Helper.php




            <?php 

            namespace AppHelpers;
            class Helper{
            public static function MoneyFormat($number){}
            }



            /config/app.php




            define alias



            'Helper' => AppHelpersHelper::class,



            /app/Http/Controllers/YourController.php




            use Helper;


            and use it where ever you want like



            Helper::MoneyFormat($price)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 13 '18 at 9:28

























            answered Nov 13 '18 at 9:04









            Gaurav RaiGaurav Rai

            753619




            753619













            • it show the error undefined class error when i define alias.

              – lun7code
              Nov 13 '18 at 9:24











            • Have you created helper file /app/Helpers/Helper.php updated my answer

              – Gaurav Rai
              Nov 13 '18 at 9:26













            • my path is here ---> app/helpers.php

              – lun7code
              Nov 13 '18 at 9:30



















            • it show the error undefined class error when i define alias.

              – lun7code
              Nov 13 '18 at 9:24











            • Have you created helper file /app/Helpers/Helper.php updated my answer

              – Gaurav Rai
              Nov 13 '18 at 9:26













            • my path is here ---> app/helpers.php

              – lun7code
              Nov 13 '18 at 9:30

















            it show the error undefined class error when i define alias.

            – lun7code
            Nov 13 '18 at 9:24





            it show the error undefined class error when i define alias.

            – lun7code
            Nov 13 '18 at 9:24













            Have you created helper file /app/Helpers/Helper.php updated my answer

            – Gaurav Rai
            Nov 13 '18 at 9:26







            Have you created helper file /app/Helpers/Helper.php updated my answer

            – Gaurav Rai
            Nov 13 '18 at 9:26















            my path is here ---> app/helpers.php

            – lun7code
            Nov 13 '18 at 9:30





            my path is here ---> app/helpers.php

            – lun7code
            Nov 13 '18 at 9:30


















            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%2f53277094%2fcall-to-undefined-function-changes-on-helper-php-file-but-still-cant-call-prese%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







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()