Where do I put Laravel 4 helper functions that can display flash messages?

后端 未结 8 896
孤街浪徒
孤街浪徒 2021-02-12 14:07

I\'ve written a simple display_messages() function that will search Session::get(\'errors\') for flash data and echo it to the screen.

Where do

8条回答
  •  走了就别回头了
    2021-02-12 14:45

    Create a folder helpers within your app folder and create a file application_helper.php. With such code:

    // app/helpers/application_helper.php
    
    function display_messages()
    {
      exit('Yes');
    }
    

    Then open your composer.json file in root. autoload app/helpers/application_helper.php with composer files.

    "autoload": {
    ....
    
        "files": [
            "app/helpers/application_helper.php"
        ]
    

    Done, you can now call display_messages().

    Some autoloaders may require you to run composer dump command for the first time.

提交回复
热议问题