Engineering note · Laravel

Modify Response with Middleware

By Published Updated

Laravel

Modify or enhance responses using middleware, such as adding headers, manipulating content, or handling exceptions.

CODE SAMPLE Code snippet
// Example middleware to add custom headers
public function handle($request, Closure $next)
{
    $response = $next($request);
    $response->header('X-App-Name', config('app.name'));
    return $response;
}

More engineering notes

Sanitize Input to Prevent SQL Injection

Always use Eloquent ORM or Laravel's query builder to interact with the database, which automaticall...

Route Model Binding

Route model binding is used to automatically inject model instances into controllers, this will help...