How to make global function and get the data returned in Laravel 5

By Abaij

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 AppHttpControllers;
use AppHttpGeneral;
use IlluminateHttpRequest;
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 'AppHttpGeneral' not found. And then how I can
Anyone can help would be appreciated.

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273