Laravel 9.8 Released | Laravel News

0
31
laravel9-1646792144.jpg


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:

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:

1<input type="text" name="name" value="{{ old('name', $user->name) }}">

2 

3{{-- 🔥 --}}

4<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:

1use PDOException;

2use Psr\Log\LogLevel;

3 

4/**

5 * A list of exception types with their corresponding custom log levels.

6 *

7 * @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>

8 */

9protected $levels = [

10 PDOException::class => LogLevel::CRITICAL

11];

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:

1public function boot()

2{

3 Blade::anonymousComponentNamespace('flights.bookings', 'flights');

4}

Here’s an example of anonymous component usage:

1<x-flights::panel :flight="$flight" />

Set Factory Method

Ralph J. Smit contributed a model factory set() method to set a single model attribute:

1// Before

2EloquentModel::factory()

3 ->create(['name' => 'foo']);

4 

5// After

6EloquentModel::factory()

7 ->set('name', 'foo')

8 ->create();

9 

10// Before

11EloquentModel::factory()

12 ->someMethod()

13 ->create(['country' => 'NL']);

14 

15// After

16EloquentModel::factory()

17 ->someMethod()

18 ->set('country', 'NL')

19 ->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.





Source link

Leave a reply

Please enter your comment!
Please enter your name here