maurobonfietti / slim4-api-skeleton

Useful skeleton for RESTful API development with PHP and Slim 4.
http://bit.ly/2nNNOZi
MIT License
132 stars 32 forks source link

Missing middleware skeleton #30

Closed HRankit closed 3 years ago

HRankit commented 4 years ago

Please add basic before and after middleware skeleton to the project. It'll help everyone a lot.

GoldraK commented 4 years ago

Hello, You can do it in the following way:

  1. Create the Middleware folder inside the App

  2. Create the middleware you need here you have the documentation to create it

http://www.slimframework.com/docs/v4/concepts/middleware.html

  1. In the Routes file you import it with:

use App\Middleware\Auth;

  1. You use it in the route or group you want with ->add(new Auth());
maurobonfietti commented 4 years ago

Yeap.

I'm working on this skeleton project.

In the meantime, you can do it step by step like @GoldraK says.

Also, I have another repo with some examples using Slim and Middlewares.

Create an Auth Middleware: https://github.com/maurobonfietti/rest-api-slim-php/blob/master/src/Middleware/Auth.php#L12

Using this Auth Middleware: https://github.com/maurobonfietti/rest-api-slim-php/blob/master/src/App/Routes.php#L22