1

I want to be able to call some functions defined in Controller Class, to any view. All controllers extends Controller class.

For example i want to call the function which is define in Controller class:

public function makeSeoLink($str)
{
    // code logic....
    return strtolower($str);
}

where HomeController extends it:

class HomeController extends Controller
{
  return view('home.homepage');
{

in homepage view {{ makeSeoLink('asfasfs') }} or {{ $this->makeSeoLink('asfasfs') }} not working to call that function:

"Call to undefined function makeSeoLink()"

What i have done wrong?

calin24
  • 905
  • 3
  • 21
  • 43

1 Answers1

0

using an instance of controller class in index method works:

class HomeController extends Controller
{
    public function index(Controller $tools){
      return view('home.homepage')->with('tools', $tools);
    }  
}

and in the view just use the variable $tools to call the method

 {{ $tools->makeSeoLink('') }}
calin24
  • 905
  • 3
  • 21
  • 43