accessing api
Workaja opened this issue · comments
sorry for newbie question, how to accessing the api from controller, which non modular controller
my controller located on: app\http\controllers\admincontroller.php
inside of the controller, I try to call Module::all();
but it return error:
Class 'App\Http\Controllers\Module' not found
I assume it very fresh install with php 7 (xampp) and laravel 5.7
Need to reference the namespace properly 👍 Because Module
is a registered facade, it's located at the root namespace, so you need to do one of these two things to access it properly:
- Add a forward slash when you use the facade, which will tell PHP that this can be found at the root namespace:
\Module::all()
-
Inform PHP where the
Module
facade is located by specifying ause
statement in your class, then you may simply useModule::all()
without the forward slash in your code:<?php use Module; ... class YourController extends Controller { ...
There's an excellent article on understanding namespaces on Dayle Rees' blog that I recommend, found here: https://daylerees.com/php-pandas-namespaces/
Hope this helps 👍