Creating a new Module

In this section we will create a new Caffeinated Module called Widgets, and use it to define some /widgets API Endpoints. To create a Caffeinated Module we will use the Laravel Artisan command line interface.

To use Artisan within Elentra ME, it is necessary to navigate to the location where the API is included in Elentra ME. If you are using Docker, you will need to do this from the Docker container.

# log into the Docker container
docker exec -it elentra-developer bash
# navigate to Elenta ME
cd /var/www/vhosts/elentra-1x-me
# navigate to the Elentra API
cd www-root/core/library/vendor/elentrapackages/elentra-1x-api
php artisan module:list

This should return output something like this:

+------+-------------+-------------+----------------------------------------------------------------+----------+
| #    | Name        | Slug        | Description                                                    | Status   |
+------+-------------+-------------+----------------------------------------------------------------+----------+
| 9001 | Assessments | assessments | API Endpoints for the Entrada Assessments                      | Enabled  |
| 9001 | Logbook     | logbook     | This module is responsible for Logbook management.             | Enabled  |
| 9001 | User        | user        | REST API endpoints for the current user                        | Enabled  |
| 9001 | Notices     | notices     | REST API Endpoints for Notices                                 | Enabled  |
| 9001 | Sandbox     | sandbox     | Example of a module that integrates into the Entrada frontend. | Enabled  |
| 9001 | Locations   | locations   | Locations REST end point                                       | Enabled  |
| 9001 | Admissions  | admissions  | API Endpoints for the ADM flavor of Entrada                    | Disabled |
| 9001 | Clinical    | clinical    | This is the description for the Clinical module.               | Enabled  |
| 9001 | Events      | events      | Endpoint for events                                            | Enabled  |
| 9001 | Portfolio   | portfolio   | This module is responsible for Portfolio management.           | Enabled  |
+------+-------------+-------------+----------------------------------------------------------------+----------+

You can get help with Artisan commands by using help:

php artisan help
# or to get help for a specific command
php artisan help <command>

The Caffeinated Modules package we are using adds support for managing the modules through artisan. Create the Widget module.

php artisan make:module Widgets

This will start a wizard. Version and Description can be whatever you like.

*-----------------------------------------------*
|                                               |
|              Copyright (c) 2016               |
|                  Shea Lewis                   |
|                                               |
|         Thanks for using Caffeinated!         |
*-----------------------------------------------*
______  ___     _________      ______
___   |/  /___________  /___  ____  /____________
__  /|_/ /_  __ \  __  /_  / / /_  /_  _ \_  ___/
_  /  / / / /_/ / /_/ / / /_/ /_  / /  __/(__  )
/_/  /_/  \____/\__,_/  \__,_/ /_/  \___//____/  

*-----------------------------------------------*
|                                               |
|          Step #1: Configure Manifest          |
|                                               |
*-----------------------------------------------*


 Please enter the name of the module: [Widgets]:
 > 

 Please enter the slug for the module: [widgets]:
 > 

 Please enter the module version: [1.0]:
 > 

 Please enter the description of the module: [This is the description for the Widgets module.]:
 > 

You have provided the following manifest information:
Name:                       Widgets
Slug:                       widgets
Version:                    1.0
Description:                This is the description for the Widgets module.
Basename (auto-generated):  Widgets
Namespace (auto-generated): Entrada\Modules\Widgets

 If the provided information is correct, type "yes" to generate. (yes/no) [no]:
 > yes

Thanks! That's all we need.
Now relax while your module is generated.
 2/2 [============================] 100%
Module generated successfully.

This will create a new directory Widgets under app/Modules, and populate a number of directories and files.

Laravel as a PHP framework can act as an API and a front-end web server. For our purposes we only care about the API, so after creating the Module there is some cleanup to do.

  • Remove the fileWidgets/Routes/web.php

  • Edit the file Widgets/Providers/RouteServiceProvider.php and remove the mapWebRoutes() function

  • Also remove the reference to mapWebRoutes() in the map() function

Next we will create a controller and routes for our Widgets.

Last updated