DEV Community

Mahmoud Ramadan
Mahmoud Ramadan

Posted on

Easy Model v2.1.0: Less Eloquent Boilerplate, More Control

Easy Model v2.1.0 Release

πŸš€ Easy Model v2.1.0 is here!

Eloquent makes simple queries easy. But as an application grows, the same filtering, sorting, searching, eager loading, pagination, and relationship logic can start appearing across multiple controllers and repositories.

A typical endpoint can quickly turn into a long chain of conditional query logic:

$query = User::query();

$query->when($request->filled('search'), function ($query) use ($request) {
    $query->where('name', 'like', '%' . $request->search . '%');
});

$query->when($request->filled('sort'), function ($query) use ($request) {
    $query->orderBy($request->sort, $request->direction ?? 'asc');
});

$query->with($request->input('include', []));

$users = $query->paginate($request->input('per_page', 15));
Enter fullscreen mode Exit fullscreen mode

Easy Model helps move this kind of repetitive query logic into reusable model capabilities.

For example, request-driven queries can handle filters, sorting, includes, and searches:

$users = User::fromRequest()->paginate();
Enter fullscreen mode Exit fullscreen mode

You can also build more specific queries with dedicated methods:

User::query()
    ->whereDateBetween('created_at', $from, $to)
    ->whereJson('settings->role', 'admin')
    ->withCount('posts')
    ->orderByRelationship('posts', 'created_at')
    ->paginate();
Enter fullscreen mode Exit fullscreen mode

What’s new in v2.1.0

  • πŸ”Ž Request-Driven Queries β€” build controlled filters, sorts, includes, and searches from request parameters.
  • βš™οΈ Conditional Queries β€” apply query logic with when() and unless().
  • πŸ”— Smarter Relationships β€” dynamic eager loading, relationship counts, and relationship-based keyword searches.
  • 🎯 Select & Pagination β€” control selected columns and use multiple pagination strategies.
  • πŸ“… Date & JSON Filters β€” query dates, periods, and JSON data with dedicated methods.
  • πŸ—‘οΈ Soft Deletes β€” query, restore, and permanently delete soft-deleted models.
  • ⚑ Mass Insert & Upsert β€” handle bulk database operations with optional model events.
  • πŸ”„ Relationship Ordering β€” improved joins and table aliasing for complex relationship queries.
  • πŸ§ͺ Better Testing β€” expanded coverage with Orchestra Testbench and PHPUnit.

The goal is simple: reduce repetitive Eloquent code while giving developers more control over complex queries.

πŸ‘‰ Check out Easy Model:

https://github.com/mahmoudmohamedramadan/easy-model

Top comments (0)