caffeinated / modules

:package: Modules package for Laravel

Home Page:https://caffeinatedpackages.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

commented

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:

  1. Add a forward slash when you use the facade, which will tell PHP that this can be found at the root namespace:
\Module::all()
  1. Inform PHP where the Module facade is located by specifying a use statement in your class, then you may simply use Module::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 👍