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