Route::query() and Model defaults() in Laravel 13.35
Explore ergonomic developer improvements in Laravel 13.35 including direct query route bindings and declarative Eloquent model attribute defaults.
Route::query() and Model defaults() in Laravel 13.35
Laravel 13.35 brings two highly requested quality-of-life enhancements for routing and Eloquent models.
Declarative Model Defaults
Rather than declaring an $attributes array or setting values inside model lifecycle hooks, you can now define default attribute states declaratively:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Invoice extends Model
{
protected function defaults(): array
{
return [
'status' => 'draft',
'currency' => 'USD',
'tax_rate' => 0.15,
];
}
}
Route Query String Helper
Accessing sanitized query parameters directly within route closures is now cleaner than ever with Route::query() helpers, avoiding unnecessary dependency injection when handling lightweight redirects.