laravel

Laravel API resources for JSON transformation

API resources transform Eloquent models into JSON responses with full control over structure and data exposure. I create resource classes that extend JsonResource and define a toArray() method returning the desired JSON structure. Resources hide sensi

Laravel queues for background job processing

Queues offload time-consuming tasks to background workers, keeping web requests fast. I create job classes that implement the ShouldQueue interface and define a handle() method. Jobs are dispatched with dispatch() or Job::dispatch() and run asynchrono

Laravel accessors and mutators for attribute handling

Accessors and mutators transform model attributes when retrieving or setting values. Accessors format data for presentation—converting cents to dollars, concatenating names, or generating computed properties. Mutators normalize input—hashing passwords

Laravel Sanctum for API authentication

Laravel Sanctum provides lightweight API authentication for SPAs and mobile apps. For SPAs on the same domain, Sanctum uses Laravel's session cookies with CSRF protection. For mobile apps or third-party clients, it issues API tokens stored in a person

Laravel file storage with disk abstraction

Laravel's filesystem abstraction treats local, S3, FTP, and other storage identically. I configure disks in config/filesystems.php with drivers and credentials. The Storage facade provides methods like put(), get(), delete() that work across all disks

Laravel custom validation rules

Custom validation rules encapsulate complex validation logic in reusable classes. I create rule classes implementing ValidationRule with a validate() method receiving the attribute, value, and fail closure. Rules access databases, call APIs, or perfor

Laravel database transactions for data integrity

Database transactions ensure multiple database operations succeed or fail together, maintaining data consistency. I wrap related operations in DB::transaction() which automatically commits on success and rolls back on exceptions. For manual control, I

Laravel cache strategies for performance

Caching dramatically improves performance by storing expensive computations or database queries. Laravel supports multiple cache drivers—Redis, Memcached, file, database. I use Cache::remember() to fetch or compute and cache values with expiration. Ca

Laravel HTTP client for API consumption

Laravel's HTTP client wraps Guzzle with a fluent, expressive API for consuming external APIs. The Http facade provides methods like get(), post(), put(), and delete(). I chain withHeaders(), withToken(), and withBasicAuth() for authentication. The ret

Laravel policies for authorization

Policies organize authorization logic around models, keeping permission checks clean and reusable. Each policy method corresponds to an action—view, create, update, delete. I call policies via the Gate facade or authorize() helper in controllers. The

Laravel test writing with PHPUnit

Laravel's testing suite built on PHPUnit makes writing tests straightforward. Feature tests simulate HTTP requests and assert responses, while unit tests focus on individual methods. I use database transactions or RefreshDatabase to reset the database

Laravel event-driven architecture with listeners

Events and listeners decouple application logic, making code modular and testable. When significant actions occur—user registered, order placed—I fire events. Multiple listeners can respond to one event without the event knowing about them. Events are