I just read this post to make a global function which is able to be accessed from any controller. But I don't understand how it works.
I want to make variable 'services' accessible from any controller. So, I make General.php and put it in app/Http. Here is the code.
<?php
class General {
public function getServices() {
$services = "SELECT * FROM products";
return $services;
}
}
And in the controller I include it
<?php
namespace App\Http\Controllers;
use App\Http\General;
use Illuminate\Http\Request;
class HomeController extends Controller {
public function index() {
$title = 'Our services';
$services = General::getServices();
return view('welcome', compact('title','services'));
}
}
When I run it I got error Class 'App\Http\General' not found
. And then how I can
Anyone can help would be appreciated.