You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 1 is for production and 2+ for local environment.
25
-
Route::processOutput(Route::dispatch(2));
50
+
Route::dispatch(2);
26
51
```
27
52
28
53
### Defining routes:
@@ -53,60 +78,11 @@ use in routes:
53
78
'/user/{name:a}'
54
79
```
55
80
56
-
### ~~Filters~~ Middleware:
57
-
Is identical to filters, we change the name of `filter` to `middleware`.
58
-
`Route::newMiddleware('auth', Auth::class, 'auth')` is the basic syntax for adding a middleware to our RouteCollector object. The first parameter is the name of the middleware. The second parameter is the class referenced and the third parameter the name of the function it belongs to. <br>
It's identical to filters, we renamed `filter` to `middleware`. `['auth', Auth::class, 'auth']` is the basic syntax for adding a middleware to our RouteCollector object. Each middleware must be encapsulated in an array, where each middleware carries its information within another array. The first parameter is the name of the middleware. The second parameter is the class being referenced and the third parameter the name of the function it belongs to. <br>
154
+
155
+
```php
156
+
use LionRoute\Route;
157
+
use App\Http\Middleware\Auth;
158
+
159
+
Route::init()->newMiddleware([
160
+
['auth', Auth::class, 'auth'],
161
+
['no-auth', Auth::class, 'noAuth']
162
+
]);
163
+
```
164
+
165
+
```php
166
+
// Auth Class
167
+
168
+
namespace App\Http\Middleware;
169
+
170
+
class Auth {
171
+
172
+
public function __construct() {
173
+
174
+
}
175
+
176
+
public function auth(): void {
177
+
if (!isset($_SESSION['user_session'])) {
178
+
echo(json_encode([
179
+
'status' => "error",
180
+
'message' => "user session does not exist"
181
+
]));
182
+
183
+
exit(); // exit to end the execution of the process up to that point.
184
+
}
185
+
}
186
+
187
+
public function noAuth(): void {
188
+
if (isset($_SESSION['user_session'])) {
189
+
echo(json_encode([
190
+
'status' => "error",
191
+
'message' => "user session exists"
192
+
]));
193
+
194
+
exit(); // exit to end the execution of the process up to that point.
195
+
}
196
+
}
197
+
198
+
}
199
+
```
200
+
201
+
When calling `Route::middleware()` keep in mind that the first parameter is an array loaded with data. <br>
202
+
203
+
The first index is the middleware at position `before`. <br>
204
+
The second index is optional and points to `after`. <br>
205
+
The third index is optional and indicates a `prefix` to work the middleware in a more dynamic way. <br>
206
+
207
+
Take into account that if more than 3 parameters are added, these are left over and do not generate internal errors in their operation.
0 commit comments