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

后端 未结 8 999
孤街浪徒
孤街浪徒 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:33

    I used this tutorial and i think is the easiest method: http://laravel-recipes.com/recipes/50/creating-a-helpers-file

    1. First create the file app/helpers.php
    2. Then either load it at the bottom of app\start\global.php as follows.

      // at the bottom of the file require app_path().'/helpers.php';

    Or change your composer.json file and dump the autoloader.

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

    $ composer dump-auto

    1. then you can write your functions in helpers.php and call them from anywhere

      function myfunction($result){ 
           return $result;
          }
      

提交回复
热议问题