SortBundle provides a standardized sorting interface for collections, which aligns well with Laravel applications requiring dynamic, user-driven sorting (e.g., admin panels, APIs, or frontend grids). It abstracts sorting logic, reducing boilerplate and improving consistency.?sort=-created_at,name)? If not, is this a blocker for your use case?User's posts.count)?Request validation)?created_at DESC)?orderBy) or packages like spatie/laravel-query-builder suffice with less risk?Collection and ParameterBag, so it integrates smoothly with existing Symfony-based Laravel apps.GET /users?sort=name).orderBy calls, frontend JS sorting) to identify duplication.Post) to test integration.composer require cannibal/sort-bundle.php artisan vendor:publish --provider="Cannibal\SortBundle\SortBundle".config/app.php (if not auto-discovered).config/sort.php (e.g., fields: ['name', 'created_at']).Sortable) or service to apply sorting to queries:
use Cannibal\SortBundle\Traits\Sortable;
class PostController extends Controller {
use Sortable;
public function index() {
$posts = Post::query()->getSorted($this->getSortInput());
return response()->json($posts);
}
}
FormRequest).composer.json for supported Laravel versions (likely 8.x+). May need adjustments for older versions.ORDER BY optimizations).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Malformed sort parameters | SQL errors or logic flaws | Validate inputs via Laravel’s validation. |
| Unsupported sort field | Silent failure or error | Whitelist allowed fields in config. |
| Database index missing | Slow queries | Add indexes for frequently sorted fields. |
| Bundle abandonment | Unmaintained code | Fork and maintain privately. |
| Nested sorting edge cases | Incorrect ordering | Test with complex relationships. |
getSorted() to queries) is straightforward.How can I help you explore Laravel packages today?