Mail: [email protected] Phone: +1(424)231-4091

Module's Routing

By registering routes, you let NexoPOS 4.x know how it can take the user to your routes. The routes system uses Laravel Routing. Here we'll just cover the specificity that is required to understand how the routes work for modules.

Type Of Route Files

Every module come with 2 files within the "Routes" folder that are using for routing :

  • api.php which is means to only be used for API calls. Here you'll define your API endpoints.
  • web.php which are mean for all routes that are likely to be accessible by direct access (GET) or by any other regular method. Every route that takes to a UI must be registered on a web.php file.

Further details can be found here.

Difference Between Public And Private Routes (Dashboard)

Public Routes are likely to be available for the public. These routes usually don't use "dashboard" as a prefix and most of the time don't require permissions to be accessible.

Private Routes are routes that use "dashboard" as a prefix. These routes are means to be administrative routes and design all routes that take to dashboard interfaces.

Registrating Route

Here, we'll register a route that takes to a page on the dashboard with an ending slug "foobar".

Note that here we're loading a controller that is supposed to be registered on the "Http/Controllers" folder with the filename FooBarController.php.

If you want to create a controller for your module, you can still use the command :

php artisan modules:controller {module_namespace} {controller_class_name} 

So to create a FooBarController as a controller, we'll use the following command :

php artisan modules:controller FooBar FooBarController

Protecting Routes With Permission

As you can protect menus with permissions, you can also protect routes using permissions. Here, we'll define the permission on a middleware like so.

Here, the middleware name to use is "ns.restrict" which accepts as a parameter the permission we'll require to allow access to a route. In our example, we've used "can.fly" as permission. Note that between the middleware name and the permission there is a colon (:) used as a separator.

Requesting Authentication For Certain Routes

If you would like to protect some routes with authentication, you'll need to attach a middleware to those routes. Here is an example :

We're here using the middleware "Authenticate" to protect the routes defined within the group. Note that "SubstituteBindings" is also required to ensure the model binding works for the modules.