Search results for #practicalLaravelDocs
Laravel tip. Need to validate only when a field is present but allow it to be optional? Use the `sometimes` rule! It only validates when the field exists in the request data. Link to the docs: laravel.com/docs/12.x/vali… #practicalLaravelDocs
Recently I found a cool way to write routes Not to repeat the controller name every line in Laravel It is fast to write and simple to look First photo is old way Second a new way #Laravel #practicalLaravelDocs
Laravel tip. Need conditional task execution based on environment, time, or custom logic? Use `when()`, `between()`, `environments()`, and other constraint methods to run tasks only when conditions are met. Link to the docs: laravel.com/docs/12.x/sche… #practicalLaravelDocs
Laravel tip. Need tasks to run faster than every minute? Laravel scheduler supports sub-minute intervals down to every second! Link to the docs: laravel.com/docs/12.x/sche… #practicalLaravelDocs
Laravel tip. Combine route name prefixes with route groups for consistent naming! Use `Route::name()` to automatically prefix all route names in a group. Also, did you know about nested prefixes? Link to the docs: laravel.com/docs/12.x/rout… #practicalLaravelDocs
Laravel tip. Customize your application's route loading with `withRouting()` in `bootstrap/app.php`! Create custom route files, change API prefixes, or take complete control over route registration. Link to the docs: laravel.com/docs/12.x/rout… #practicalLaravelDocs
Laravel tip. Want to include soft-deleted models in route model binding? Use `withTrashed()` to allow access to deleted records through routes. Link to the docs: laravel.com/docs/12.x/rout… #practicalLaravelDocs
Laravel tip. Working with PHP Enums? Route parameters can automatically validate and inject Enum values! Laravel returns 404 for invalid enum values, keeping your controllers clean. Link to the docs: laravel.com/docs/12.x/rout… #practicalLaravelDocs
Laravel tip. Need different behavior for different subdomains? Use subdomain routing to handle multi-tenant apps, API versions, or region-specific content. Link to the docs: laravel.com/docs/12.x/rout… #practicalLaravelDocs
Laravel tip. Need to protect sensitive routes like making repositories public or deleting accounts? Add `password.confirm` middleware to ANY route. Users will need to re-enter their password before proceeding. Link to docs: laravel.com/docs/12.x/auth… #practicalLaravelDocs
Laravel tip. Handle 404s gracefully with fallback routes! Instead of showing generic error pages, create custom fallback routes that execute when no other route matches. Link to the docs: laravel.com/docs/12.x/rout… #practicalLaravelDocs
Laravel tip. Need to validate route parameters format? Use `where()` constraints with regex patterns or helper methods to ensure clean URLs and prevent invalid data from reaching your controllers. Link to the docs: laravel.com/docs/12.x/rout… #practicalLaravelDocs
It's still mind-blowing to me. For months, I've been posting Laravel tips with #practicalLaravelDocs which are LITERALLY from the docs. Just re-shaped with better examples. And they are *by far* the most Liked tweets on my feed. People prefer my tweets over reading docs :)
It's still mind-blowing to me. For months, I've been posting Laravel tips with #practicalLaravelDocs which are LITERALLY from the docs. Just re-shaped with better examples. And they are *by far* the most Liked tweets on my feed. People prefer my tweets over reading docs :)
Laravel tip. Skip writing controllers for simple redirects and static pages! Use `Route::redirect()` for redirects and `Route::view()` for returning views directly. Link to docs: laravel.com/docs/12.x/rout… #practicalLaravelDocs
Laravel tip. Use `response()->streamDownload()` to create downloads without writing to disk. Generate files on-the-fly and stream directly to user. Link to the docs: laravel.com/docs/12.x/resp… #practicalLaravelDocs
Laravel tip. Use `response()->file()` to display files in browser instead of downloading them! Perfect for showing PDFs or documents inline. Link to the docs: laravel.com/docs/12.x/resp… #practicalLaravelDocs Note: browser support varies by browser and user settings.
Laravel tip. Working with JSON APIs? Use dot notation to access nested JSON data directly through `input()` method. No need to manually decode JSON or navigate arrays! Link to the docs: laravel.com/docs/12.x/requ… #practicalLaravelDocs
Laravel tip. You prefer Collections over arrays? You can get request data as a Collection instead of an array! Use `collect()` method and immediately continue with data manipulation. Link to the docs: laravel.com/docs/12.x/requ… #practicalLaravelDocs
Laravel tip. Need to check request path patterns or route names without complex regex? Use `is()` for path patterns and `routeIs()` for named routes. Both support wildcards for flexible matching. Link to the docs: laravel.com/docs/12.x/requ… #practicalLaravelDocs
Laravel tip. Want to conditionally execute code based on input presence without writing nested if statements? Use `whenHas()` and `whenFilled()` methods for cleaner conditional logic in your controllers. Link to the docs: laravel.com/docs/12.x/requ… #practicalLaravelDocs