Laravel Controller – call function inside another function

Solution:

You can create another function in Controller file and call it:

private function foo($view)
{
    $blogs = Blog::orderBy('id', 'desc')->where('status', '1')->paginate(3);
    return view($view)->withBlogs($blogs);
}

And then call it:

public function getIndex() {
    return $this->foo('index-page');
}

public function getAbout() {
    return $this->foo('about-page');
}

If you want to create a function that can be called everywhere, you can create a static function in a class. Ex:

public static function foo()
{
    return "foo";
}

and then call it:

NameOfClass::foo();