Skip to content

Commit 6ea5dae

Browse files
committed
updated readme.md
1 parent 4f240fe commit 6ea5dae

File tree

1 file changed

+15
-44
lines changed

1 file changed

+15
-44
lines changed

README.md

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ A simple, lightweight, and powerful PHP Router with rich features like Middlewar
1616

1717
- Supports `GET` `POST` `PUT` `PATCH` and `DELETE` HTTPS verbs
1818
- The methods that the router supports are - `get()` `post()` `put()` `patch()` `delete()` `match()` `any()`
19-
- Named Routes
2019
- Middleware
20+
- Controller
21+
- Named Routes
2122
- Regular Expression Constraints for parameters
2223
- Fallback method
2324
- Easy way to manage request
@@ -33,6 +34,7 @@ A simple, lightweight, and powerful PHP Router with rich features like Middlewar
3334
- **[Directories](#Directories)**
3435
- **[Routes](#Routes)**
3536
- **[Middlewares](#middlewares)**
37+
- **[CSRF Protection](#CSRF-Protection)**
3638
- **[Controllers](#Controllers)**
3739
- **[Request](#Request)**
3840
- **[Handle Html View Content File](#Handle-Html-View-Content-File)**
@@ -414,17 +416,6 @@ If you are defining a route that redirects to another URI, you may use the `redi
414416
$router->redirect('/here', '/there');
415417
```
416418

417-
## CSRF Protection:
418-
419-
Remember, any HTML forms pointing to POST, PUT, PATCH, or DELETE routes that are defined in the web routes file should include a CSRF token field. Otherwise, the request will be rejected:
420-
421-
```php
422-
<form method="POST" action="/profile">
423-
<?=setCsrf()?>
424-
...
425-
</form>
426-
```
427-
428419
## Middlewares:
429420

430421
`app/Middlewares`: Middleware provides a convenient mechanism for inspecting and filtering HTTP requests entering your application.
@@ -499,38 +490,6 @@ Router::put('/users/:id', function(){
499490
})->middleware(['auth','csrf']);
500491
```
501492

502-
<!-- #### Middleware Parameters:
503-
504-
**We can optionally pass parameters to the middleware.**
505-
506-
```php
507-
Router::get('/profile', [AuthenticatedController::class, 'show'])->name('profile')->middleware('auth:parameter');
508-
```
509-
510-
Multiple parameters:
511-
512-
```php
513-
Router::get('/profile', [AuthenticatedController::class, 'show'])->name('profile')->middleware('auth:parameter');
514-
``` -->
515-
<!--
516-
Handle middleware arguments:
517-
518-
```php
519-
public function handle(Request $request, array $guards) {
520-
if (!empty($guards)) {
521-
// Handle middleware arguments.
522-
foreach ($guards as $guard) {
523-
if (!Auth::guard($guard)->check() && $guard === 'admin') {
524-
return redirect('/admin/login');
525-
}
526-
}
527-
} elseif (!Auth::check()) {
528-
return redirect('/login');
529-
}
530-
return;
531-
}
532-
``` -->
533-
534493
#### Set default middlewares:
535494

536495
If you want to set some middleware to Https verbs by default, you can do that very easily, The defined middleware will run when that https method request is handled:
@@ -545,6 +504,18 @@ Open `app/config/middleware.php`
545504
'delete' => [ 'csrf', 'auth' ],
546505
```
547506

507+
## CSRF Protection:
508+
509+
Anytime you define a "POST", "PUT", "PATCH", or "DELETE" HTML form in your application, you should include a hidden CSRF _token field in the form so that the CSRF protection middleware can validate the request, Otherwise, the request will be rejected. For convenience, you may use the `setCsrf()` function to generate the hidden token input field:
510+
511+
512+
```php
513+
<form method="POST" action="/profile">
514+
<?=setCsrf()?>
515+
...
516+
</form>
517+
```
518+
548519
## Controllers:
549520

550521
`app/Controllers`: Controllers respond to user actions (submitting forms, show users, view data, and any action etc.). Controllers are classes that extend the BaseController class.

0 commit comments

Comments
 (0)