Tuesday 26 November 2019

Laravel 5.1 Composer.json Call File in Autoload



I just want to create a global function in laravel 5.1
I create a file in App/Helper.php



Helper.php



     namespace App\Helpers;
class Helpers {

public function somethingOrOther()
{
return "Yes It is";
}
}


test.blade.php



Helpers::somethingOrOther();



But it is not working



Every Time I gon a fatel error like "Class 'App\Helpers' not found"



Please Help me


Answer



Since you are Helper method are statics you could add your helper class your config/app alias just like a Facade, like so:




'aliases' => [
//'Helpers'=> 'App\Helpers\Helpers', //for Laravel 5.0
'Helpers'=> App\Helpers\Helpers::class, //for Laravel 5.1
]


check this question



What is the best practice to create a custom helper function in php Laravel 5?


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...