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

1
  • What happens if you try \Helper::homePageURL(); ? Commented Jan 24, 2018 at 13:22

1 Answer 1

2

In your controller, add this line at top-

use Helper;

Or you can do as @Eleazar Resendez says-

return \Helper::homePageURL();
Sign up to request clarification or add additional context in comments.

2 Comments

its working fine when i use in route but not working in controller
@SherazKhan please see my updated answer and make a quick try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.