Work In progress! No support given. You are on your own.
Introduction
WemX has an advanced modular system. Modules allow you to extend the capabilities of your WemX panel. Modules are essentially a mini Laravel application with routes, providers, models, controllers, views and more. We'd love for you to develop modules and add them to the WemXModules library.
In this guide, we'll dive into the depths of WemX modules. Before we begin, you should definitely have programming experience with PHP and Laravel. What will we cover in this course? We will develop a module that creates a page in the customer area and in the admin area. On the admin side, we will create a settings page. On the client side, we will display simple text. We will also look at how to save and retrieve the settings and simply display them on the page in this example.
Creating a new Module
Using SSH you may run the following command to generate a Module:
php artisan module:make <module-name>
In our example, we will develop an ExampleModule, so let's call it ExampleModule.
We will now use our command (shown below) in the directory of our development environment. In my chase /var/www/wemx-dev/
php artisan module:make ExampleModule
You will gave a newly created folder within in Folder Modules/<module-name>
In our case Modules/ExampleModule
You can use ssh to remotly work on it. VSCode and PHPStorm have this feature. And I will not use it here in the guide. Here I just download the Module so its on my PC and afer working in it I upload the module to the server.
Before we start developing the Module we need to remove one line of code to fix the page
Here we have a variable error that need to be fixed first.
Open the file Routes/web.php
Replace all imports with use with
use Illuminate\Support\Facades\Route;
use ExampleModule\ExampleModuleController;
After all this we shoud have a route file that looks like that:
<?php
use Illuminate\Support\Facades\Route;
use ExampleModule\ExampleModuleController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::group(['middleware' => 'auth', 'prefix' => 'admin'], function () {
Route::get('/examplemodule/client', [ExampleModuleController::class, 'client'])->name('examplemodule.index');
});
Route::group(['middleware' => ['auth', 'permission:admin.view'], 'prefix' => 'admin'], function () {
Route::get('/admin/examplemodule', [ExampleModuleController::class, 'admin'])->name('examplemodule.admin');
});
We fist need to prepare our config file.
Open config/config.php and now you need to think what you need in the folowing is my config I will use for this Module but there is also a snippet for every type.
For creating the Theme we need to prepare our folder structure.
Go into the Resources/views folder. In there delete everything
Then you need to create two folders in the views directory. The first directory you name client and the second one you name admin. It shoud look like this:
Then we need to prepare the Controller. Here I will just show a example, if you need to do more then just display a view fille you need to learn laravel.
<?php
namespace Modules\ExampleModule\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
class ExampleModuleController extends Controller
{
/**
* Display a listing of the resource.
*/
public function admin()
{
return view('examplemodule::admin.admin');
}
public function client()
{
return view('examplemodule::client.client');
}
}
For this to work we need to create 2 view filles. One in the client folder and one in the admin folder.
Create a file called admin.blade.php in the admin folder.