Laravel 9.8 Released
The Laravel team released 9.8.xxxx with accessing default form data from an Eloquent model, custom log levels per exception type, discovering anonymous components in additional paths, and more:
Laravel 9.8.0 is available today and includes several cool new features! 🔥
— Taylor Otwell 🪐 (@taylorotwell) April 12, 2022
First, a quality of life boost for the "old" helper. You can now pass a model as the second, "default" argument. The function will assume the attribute name based on the first argument. ✅ pic.twitter.com/1Mee6Tv20j
The "old" Form Helper Accepts a Model
Andrew Arscott contributed an update to the old()
helper that allows a model as the second default argument:
<input type="text" name="name" value="{{ old('name', $user->name) }}">
{{-- 🔥 --}}
<input type="text" name="name" value="{{ old('name', $user) }}">
Allow a Custom Log Level in Exception Handling
Tom Witkowski contributed the ability to customize the log level for reported exceptions in the exception handler:
use PDOException;
use Psr\Log\LogLevel;
/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
PDOException::class => LogLevel::CRITICAL
];
See Pull Request #41925 for implementation details.
Discover Anonymous Blade Components in Additional Paths
Ralph J. Smit contributed the ability to discover anonymous Blade components in additional paths:
public function boot()
{
Blade::anonymousComponentNamespace('flights.bookings', 'flights');
}
Here's an example of anonymous component usage:
<x-flights::panel :flight="$flight" />
Set Factory Method
Ralph J. Smit contributed a model factory set() method to set a single model attribute:
// Before
EloquentModel::factory()
->create(['name' => 'foo']);
// After
EloquentModel::factory()
->set('name', 'foo')
->create();
// Before
EloquentModel::factory()
->someMethod()
->create(['country' => 'NL']);
// After
EloquentModel::factory()
->someMethod()
->set('country', 'NL')
->create();
Release Notes
You can see the complete list of new features and updates below and the diff between 9.7.0 and 9.8.0 on GitHub.
v9.8.0 - 2022-04-12
Added
- Added inbound option to CastMakeCommand (#41838)
- Added a way to retrieve the first column of the first row from a query (#41858)
- Make DatabaseManager Macroable (#41868)
- Improve Str::squish() (#41877, #41924)
- Added option to disable cached view (#41859)
- Make Connection Class Macroable (#41865)
- Added possibility to discover anonymous Blade components in other folders (#41637)
- Added
Illuminate/Database/Eloquent/Factories/Factory::set()
(#41890) - Added multibyte support to string padding helper functions (#41899)
- Allow to use custom log level in exception handler reporting (#41925)
Fixed
- Illuminate/Support/Stringable::exactly() with Stringable value (#41846)
- Fixed afterCommit and RefreshDatabase (#41782)
- Fix null name for email address in
Illuminate/Mail/Message
(#41870) - Fix seeder property for in-memory tests (#41869)
- Fix empty paths for server.php (#41933)
- Fix ExcludeIf constructor (#41931)
Changed
- Set custom host to the serve command with environment variable (#41831)
- Add handling of object being passed into old method in Model (#41842)
- Catch permission exception when creating directory (#41871)
- Restore v8 behaviour of base query for relations (#41918, #41923)
- Standardize withCount() & withExists() eager loading aggregates (#41914)