Latest Premium Tutorial
-
· 11 mins, 2097 words · premium
Laravel Reverb Demo: Real-Time Notification on Completed Task
Some Laravel tasks are running in the background. What if you want to "listen" for those events to finish? Let's implement exactly this real-time feedback with the Reverb server.
Newest content
-
· 2 mins, 215 words
This Week: 40% Discount for Yearly and Lifetime Plans!
-
· 1 min, 107 words
Laravel 11: New Artisan "make:trait" Command
-
Random Quick Laravel Tip:
Sorting Your API ResultsSingle-column API sorting, with direction control
// Handles /dogs?sort=name and /dogs?sort=-nameRoute::get('dogs', function (Request $request) {// Get the sort query parameter (or fall back to default sort "name")$sortColumn = $request->input('sort', 'name');// Set the sort direction based on whether the key starts with -// using Laravel's Str::startsWith() helper function$sortDirection = Str::startsWith($sortColumn, '-') ? 'desc' : 'asc';$sortColumn = ltrim($sortColumn, '-');return Dog::orderBy($sortColumn, $sortDirection)->paginate(20);});we do the same for multiple columns (e.g., ?sort=name,-weight)
// Handles ?sort=name,-weightRoute::get('dogs', function (Request $request) {// Grab the query parameter and turn it into an array exploded by ,$sorts = explode(',', $request->input('sort', ''));// Create a query$query = Dog::query();// Add the sorts one by oneforeach ($sorts as $sortColumn) {$sortDirection = Str::startsWith($sortColumn, '-') ? 'desc' : 'asc';$sortColumn = ltrim($sortColumn, '-');$query->orderBy($sortColumn, $sortDirection);}// Returnreturn $query->paginate(20);}); -
· 1 min, 110 words
Laravel 11: New Artisan "make:interface" Command
-
· 1 min, 159 words
Laravel 11: New Artisan "make:enum" Command
-
· 1 min, 194 words
Laravel 11: New Artisan "make:class" Command
-
Premium Course: How to Structure Laravel 11 Projects
-
· 7 mins, 1314 words
Laravel 11: Main New Features and Changes
-
· 1 min, 171 words
Laravel 11: How to Change Default SQLite to MySQL
-
· Updated Mar 2024 · 3 mins, 477 words
Caching in Laravel with Redis: Simple Example
-
· 5 mins, 890 words
Virtual DB Columns in Laravel Migrations and MySQL
-
· 2 mins, 291 words
CarbonImmutable Class: Why You Would Need It