4

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

rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
Sam
  • 151
  • 1
  • 1
  • 9

1 Answers1

2

In your controller, add this line at top-

use Helper;

Or you can do as @Eleazar Resendez says-

return \Helper::homePageURL();
Sohel0415
  • 9,523
  • 21
  • 30