The Laravel team released 9.8 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:
// BeforeEloquentModel::factory() ->create(['name' => 'foo']); // AfterEloquentModel::factory() ->set('name', 'foo') ->create(); // BeforeEloquentModel::factory() ->someMethod() ->create(['country' => 'NL']); // AfterEloquentModel::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.
Filed in:
Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.