jeudi 10 mars 2016

Getting undefined call to function in Laravel 5.2

I am calling a simple function from a controller:

flash('my message');

flash function is inside a helpers.php file in App\Http

function flash($message)
{
    $flash = app('App\Http\Flash');

    return $flash->message($message);
}

flash function calls a Flash object

namespace App\Http;

class Flash{

     public function message($message)
     {
            session()->flash('flash_message', $message);
     }
}

Composer.json includes:

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

Ran the command - composer dump-autoload

Page is showing - Call to undefined function App\Http\Controllers\flash()

I've tried so many things! Even if I add a tiny test function into the helpers.php file I can't use it in controller.
Is this a namespace issue? I didn't think I had to add a use xxxx; at top of controller as the helpers.php is added to autoload and global?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire