Code snippets
Code snippets
Copy-ready answers to everyday coding questions, each with a short explanation. Laravel, PHP, JavaScript, SQL, Bash and more.
3 snippets tagged #validation · Show all
PHP
November 2, 2026
Laravel file upload: validate, store and get the URL
Validates an uploaded image, stores it on the public disk and builds its URL. Run php artisan storage:link once so the public disk is web-accessible.
<?php
use Illuminate\Support\Facades\Storage;
PHP
October 11, 2026
Laravel Request exists() vs has() vs filled() difference
exists() is an alias of has(), and both only check that the key was sent, even when its value is empty or null. Use filled() when you need a non-empty value and...
<?php
use Illuminate\Http\Request;
PHP
October 8, 2026
Laravel Form Request validation with custom messages
Moves validation out of the controller into a reusable class. Use it for any create or update endpoint; $request->validated() returns only the checked fields, w...
<?php
namespace App\Http\Requests;