This week, the Laravel team released v11.39, which includes a model factory class attribute, the ability to prevent destructive rollbacks, PhpRedis backoff and max retry options, and more.
Introduce the UseFactory attribute
Chris Arter contributed a UseFactory
PHP attribute to define which factory a model should use. This is useful for registering a factory for models outside of the conventional App\Models
namespace:
namespace App\SomeFeatureDomain\Models\Comment; use Database\Factories\CommentFactory;use Illuminate\Database\Eloquent\Relations\HasMany;use Illuminate\Database\Eloquent\Attributes\UseFactory; #[UseFactory(CommentFactory::class)]class Comment extends Model{ use HasFactory; // ...}
Another way to override the factory convention is defining a newFactory()
method, which still takes precedence over the UseFactory()
attribute if you happen to define both:
use Database\Factories\CommentFactory; /** * Create a new factory instance for the model. */protected static function newFactory(){ return CommentFactory::new();}
According to the pull request description, the factory resolution follows this priority:
- Static
$factory
property if defined - UseFactory attribute if present
- Convention-based factory resolution
See the Model and Factory Discovery Conventions documentation for details on how factories are loaded using Laravel's conventions.
Add Report/Log Option to Filesystem
Sávio Resende contributed throw
and report
filesystem driver options. If both are set to true
, that means that the disk will not throw exceptions and will report the errors:
'disks' => [ 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), 'throw' => false, // Suppress exceptions 'report' => true, // Enable error logging ],],
See Pull Request #54212 for details on how these options function.
Prevent Destructive Rollbacks
Rainer Bendig contributed the ability to prevent destructive RollbackCommand
operations if the app has configured preventing destructive commands with:
DB::prohibitDestructiveCommands(true);
Allow Adding a Path to the Translation Loader
Selçuk Çukur contributed a addPath()
method to add a directory for the translation loader:
It was not possible to add a new directory directly without a namespace for the translation loader. This method makes it possible to load translation lines by including a new directory directly in the loader without a namespace.
See Pull Request #54277 for details.
Add Support for phpredis Backoff and Max Retry Config Options
Petr Levtonov contributed configuration options for backoff and retry in the phpredis connector:
This pull request adds support for the ~phpredis backoff/retry~ configs.
Those settings are crucial for high performance applications. Currently I am forced to overwrite the driver in many services to leverage those configs. It would be amazing if you can merge this to support those configs out of the box.
I have confirmed with the phpredis maintainer, that those settings are currently only available to the normal Redis class, not for RedisCluster yet, so I did not add them to the cluster setup.
For reference, the PhpRedis section of the Laravel docs lists these new options.
Release notes
You can see the complete list of new features and updates below and the diff between 11.38.0 and 11.39.0 on GitHub. The following release notes are directly from the changelog:
v11.38.0
- [11.x] Replace duplicate
ValidatedInput
functions withInteractsWithData
trait by @stevebauman in https://github.com/laravel/framework/pull/54208 - [11.x] Improve
Email
validation rule custom translation messages by @SanderMuller in https://github.com/laravel/framework/pull/54202 - [11.x] Fix deprecation warnings in
optimize:clear
andoptimize
by @cosmastech in https://github.com/laravel/framework/pull/54197 - [11.x] Add support for phpredis backoff and max retry config options by @TheLevti in https://github.com/laravel/framework/pull/54191
- Introduces UseFactory attribute by @christopherarter in https://github.com/laravel/framework/pull/54065
- [11.x] Set class-string generic on
UseFactory
by @cosmastech in https://github.com/laravel/framework/pull/54215 - [11.x] switch LazyCollection::make() for new LazyCollection() by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/54216
- support style file name hashes with query strings in manifest by @newapx in https://github.com/laravel/framework/pull/54219
- [11.x] Solidify
Rule::email()
tests by @SanderMuller in https://github.com/laravel/framework/pull/54226 - [11.x] Fix line-ending mismatch in CliDumperTest::testArray and CliDumperTest::testObject by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/54222
- Add a report/log option to filesystem exceptions without throwing by @lotharthesavior in https://github.com/laravel/framework/pull/54212
- [11.x] Fix Cache component to be aware of phpredis serialization and compression settings by @TheLevti in https://github.com/laravel/framework/pull/54221
- [11.x] fix: Forcing DB Session driver to always use the write connection by @mathiasgrimm in https://github.com/laravel/framework/pull/54231
- [11.x] Fix line-ending mismatch in
BladeComponentTagCompilerTest
underIlluminate\Tests\View\Blade
by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/54233 - [11.x] Fix job not logged in failed_jobs table if timeout occurs within database transaction by @decaylala in https://github.com/laravel/framework/pull/54173
- [11.x] Fix unique job lock is not released on model not found exception, lock gets stuck. by @zackAJ in https://github.com/laravel/framework/pull/54000
- [11.x] Fix line-ending mismatch on Windows test by @AhmedAlaa4611 in https://github.com/laravel/framework/pull/54236
- Added support in DB::prohibitDestructiveCommands to preventing destructive Rollback… by @hexathos in https://github.com/laravel/framework/pull/54238
- [11.x] Add applyAfterQueryCallbacks Support to Non-Mutator Cases in pluck Method by @batinmustu in https://github.com/laravel/framework/pull/54268
- [11.x]
addPath()
Allow adding new path for translation loader. by @selcukcukur in https://github.com/laravel/framework/pull/54277