I've been having a problem loading my helpers file in Laravel 5 and calling the functions from views. The below is a quick overview of how I attempted to setup helpers within my L5 Project.
- Created a helpers.php file within app/Http;
The helpers file contains a basic function, to produce the page title.
public function full_title($title) { $base_title = 'Social Tracking Application'; if (isset($title) && $title != ''){ $comp_title = $title . " | " . $base_title; } else { $comp_title = $base_title; } return $comp_title; }Updated composer.json to autoload the new helpers file.
"autoload": { "classmap": [ "database" ], "psr-4": { "App\\": "app/" }, "files":["app/Http/helpers.php"]},
Run composer dump-autoload from the terminal.
After these steps I was under the impression that I could use my helper from views and controllers. So I placed a call to my new helper function within my main layout view by using the following:
<title> full_title($title) </title>
However when I navigate to any page I receive a FatalErrorMessage Call to Undefined Function full_title. (note the message is usually in the title bar so I move it to a body tag to view the error message).
I can't figure out what it is I'm doing wrong here, I've seen other examples of people using custom helper files in a similar manner but mine just doesn't seem to work am I missing something obvious?
I'm running this of Homestead.
full code base: https://github.com/n1k41l/SocialTrak/tree/middleware-currentUser