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/
phpartisanmodule:makeExampleModule
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
After all this we shoud have a route file that looks like that:
<?phpuseIlluminate\Support\Facades\Route;useExampleModule\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.
'user_dropdown'=> [ ['name'=>'Example Module','icon'=>'<i class="fas fa-cog"></i>','href'=>'#','style'=>'', ],// ... add more menu items ],
For the Admin Menu we have 2 options.
Normal Button
Dropdown Menu
First I will show the normal button
'admin_menu'=> [ ['name'=>'Example Module','icon'=>'<i class="fas fa-cog"></i>','href'=>'#','style'=>'', ],// ... add more menu items ],
For the dropdown we use this code
'admin_menu'=> [ ['name'=>'Giftcards','icon'=>'<i class="fas fa-gift"></i>','type'=>'dropdown','items'=> [ ['name'=>'Example','href'=>'/admin/example/menu1', ], ['name'=>'Example','href'=>'/admin/example/menu2', ], ['name'=>'Example','href'=>'/admin/giftcard/menu3', ],// ... add more menu items ], ], ],
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.
<?phpnamespaceModules\ExampleModule\Http\Controllers;useApp\Http\Controllers\Controller;useIlluminate\Http\RedirectResponse;classExampleModuleControllerextendsController{/** * Display a listing of the resource. */publicfunctionadmin() {returnview('examplemodule::admin.admin'); }publicfunctionclient() {returnview('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.