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

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

    For loading Classes:

    Create app/libraries/class/Message.php, and add class in file

    class Message {
        public static function display() {
    
        }
    }
    

    Add "app/libraries/class" to composer.json

    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php",
            "app/libraries/class"
        ]
    },
    

    Finally run composer dump-autoload in command line.

    You can access that by Message::display()

    For loading plain non-object php Functions:

    Create app/libraries/function/display_messages.php, and add function in file

    function display_messages() {
    
    }
    

    add one line in start/global.php

    require app_path().'/libraries/function/display_messages.php';
    

    You can access that just by display_messages()

提交回复
热议问题