Sam
Sam

Reputation: 151

laravel helper not working in controller

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)

enter image description here

Upvotes: 4

Views: 1953

Answers (1)

Sohel0415
Sohel0415

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

Related Questions