Code Explainers

Php code explainers

php
<?php
 
namespace App\Http\Controllers\Auth;
 

How a Laravel registration endpoint works

validation database-transactions events
Intermediate 8 steps
php
<?php
 
namespace App\Http\Controllers;
 

Handling avatar uploads in Laravel

file-upload image-processing validation
Intermediate 8 steps
php
<?php
 
namespace App\Security;
 

Secure password hashing with Argon2id in PHP

password-hashing argon2id timing-attacks
Intermediate 8 steps
php
<?php
 
namespace App\Security;
 

A fixed-window rate limiter on APCu

rate-limiting fixed-window caching
Intermediate 8 steps
php
class PostController extends Controller
{
    public function index(Request $request)
    {

Eager loading without N+1 in Laravel

eager-loading n+1 query-builder
Intermediate 9 steps
php
class PostController extends Controller
{
    public function index(Request $request): AnonymousResourceCollection
    {

Filtered, paginated JSON APIs in Laravel

eloquent query-builder api-resources
Intermediate 8 steps
php
<?php
 
namespace App\Support;
 

Grouping records with array_reduce in PHP

array-reduce grouping higher-order-functions
Intermediate 6 steps
php
<?php
 
namespace App\Console;
 

How task scheduling works in Laravel

scheduling cron fluent-api
Intermediate 7 steps
php
<?php
 
namespace App\Policies;
 

How authorization policies gate updates in Laravel

authorization policies access control
Intermediate 7 steps
php
<?php
 
final class ProductRepository
{

Safe SQL pagination with PDO in PHP

pagination input-validation prepared-statements
Intermediate 7 steps
php
<?php
 
namespace App\Http\Requests;
 

How a Laravel FormRequest validates input

validation form-request input-sanitization
Intermediate 6 steps
php
<?php
 
final class CsrfGuard
{

Building a per-form CSRF guard in PHP

csrf security sessions
Intermediate 8 steps
php
<?php
 
namespace App\Models;
 

Polymorphic comments in Laravel with morphTo

polymorphism eloquent relationships
Intermediate 5 steps
php
<?php
 
namespace App\Http\Middleware;
 

Enforcing a JSON Accept header in Laravel

middleware content-negotiation http-headers
Beginner 5 steps
php
<?php
 
function verifyJwt(string $token, string $secret): array
{

Verifying an HS256 JWT in PHP

jwt hmac authentication
Intermediate 9 steps
php
<?php
 
class Entity
{

PHP magic methods for dynamic attributes

magic-methods overloading encapsulation
Intermediate 6 steps
php
<?php
 
namespace App\Models;
 

Accessors, mutators & casts in a Laravel model

eloquent accessors mutators
Intermediate 6 steps