Middleware
Classes to create your logic to access to your Web App or API. It´s a layer between the controllers and views.
Go to your terminal/cmd/powershell/gitBash or other console tool and type:
Then BoosterCLI makes a file in the next path:
You will see next code:
Then you could create your own logic to evaluate certain condition, many developers evaluate things like, user role, user login, permissions, status, for say something.
ex: changing name of method to evalRole
Look at line 2 and 3, there are imported the BoosterORM class to handle operations in database without create other file or create connections to database in many files.
And import User model class to access to all it´s properties like;
User->id
User->name
ect....
To call it in controllers you could go to your UsersController and in method that you prefer (we are going to use index to continue the example).
You could add the call to your Middelware classes in some methods if you want to eval just one some methods but if you want to eval and restrict access to every method ( to imagine it simple to restrict access to your views either).
then you could add a construct to your controller and call it there like this:
So you could call the logic eval just one and works with every method, in some cases is better to add middlewares one by one because not all classes eval the same or have the same permissions or some method haver more than one condition to eval.
So as simple as add two lines of code you could eval all points of access to your class UsersController that return your views :) .
Last updated
Was this helpful?