Reputation: 151
I am trying to Create helpers in laravel. when I try to open in route it works fine but when I call in the controller function it through an error
Helper.php
namespace App\Helpers;
class Helper
{
public static function homePageURL()
{
return url('/');
}
}
app
'Helper' => App\Helpers\Helper::class,
controller
public function index()
{
return Helper::homePageURL();
}
it working fine when I use this
Route::get('/envato-user-helper-demo', function () {
return Helper::homePageURL();
});
but in the controller, it shows me This error
((1/1) FatalThrowableError Class 'App\Http\Controllers\Helper' not found
)
Upvotes: 4
Views: 1953
Reputation: 9873
In your controller, add this line at top-
use Helper;
Or you can do as @Eleazar Resendez says-
return \Helper::homePageURL();
Upvotes: 2