November 20th, 2021

Laravel v8.71.0 Release Note

Laravel v8.71.0 Release Note

Laravel v8.71.0 has been released and it containes new features, bugs fixed and changes.

WHAT HAS BEEN ADDED

Nicklas Kevin Frank contributed with PR39579 that adds declined and declined_if validation rules. Here are the docs for the PR.

Mark Kremer added Arrayable/collection support for Collection::splice() replacement param. The Collection::splice()'s $replacement parameter has different behavior depending on whether a collection or array is passed in. I expected this to be the same. Example:

1$data = collect(['foo', 'baz']);
2$data->splice(1, 0, ['bar']); // array
3dump($data->all());
4 
5// Output:
6// array:3 [
7// 0 => "foo"
8// 1 => "bar"
9// 2 => "baz"
10// ]
11 
12$data = collect(['foo', 'baz']);
13$data->splice(1, 0, collect(['bar'])); // collection
14dump($data->all());
15 
16// Output:
17// array:3 [
18// 0 => "foo"
19// 1 => array:1 [
20// 0 => "bar"
21// ]
22// 2 => "baz"
23// ]

This is due to the way PHP's native array_splice method handles objects. Although, I think this is unexpected for the user. Backwards compatibility is broken for all objects which implements Enumerable, Arrayable, Jsonable, JsonSerializable or Traversable. Other types are cast to an array by the getArrayableItems() method, which is similar to what array_splice does. The latter does not break backward compatibility.

Chris Morrell Introduced @js() blade directive. While calling JsString::from($foo) or new JsString($foo) is fine in many cases, introducing a Blade directive is a nice touch for the most common scenario: echoing a JavaScript version of a PHP variable inside of Blade.

This adds a @js() directive which is just sugar on top of {{ \Illuminate\Support\JsString::from() }}:

1<!-- Directive can be used in HTML -->
2<div x-data="@js($data)"></div>
3<button @click="alert(@js($messages).errorMessage)">Show error</button>
4 
5<!-- And in script tags -->
6<script>
7let config = @js($config);
8</script>
9 
10<!-- But you'd need to use JsString inside of Blade components -->
11<x-alert :data="JsString::from($alertData)" />

Propaganistas added Enum casts to accept backed values. Before enum castable attributes first had to be instantiated (or be null) before they are accepted for casting:

1enum MyEnum: string
2{
3 case Pending = 'pending';
4}
1$model = new Model;
2$model->enum = MyEnum::Pending;

This can get verbose when handling requests:

1// Request input = ['enum' => 'pending']
2 
3$request->merge([
4 'enum' => MyEnum::from($request->input('enum')),
5]);
6 
7$model->fill(
8 $request->all()
9);

By also accepting the backed values of an enum when casting, fluent model filling will be enabled (again).

1$model = new Model;
2$model->enum = 'pending';
1// Request input = ['enum' => 'pending']
2 
3$model->fill(
4 $request->all()
5);

Brad Miller Added a method to the Macroable trait that removes all configured macros. More details here.

FIXED

  • Fixed auto-generated Markdown views (#39565)
  • DB command: Cope with missing driver parameters for mysql (#39582)
  • Fixed typo in Connection property name in Illuminate/Database/Connection (#39590)
  • Fixed: prevent re-casting of enum values (#39597)
  • Casts value to the int in Illuminate/Database/Query/Builder::limit() (62273d2)
  • Fix $component not being reverted if component doesn't render (#39595)

CHANGED

  • make:model --all flag would auto-fire make:controller with --requests (#39578)
  • Allow assertion of multiple JSON validation errors. (#39568)
  • Ensure cache directory permissions (#39591)
  • Update placeholders for stubs (#39527)

More details here.

Statamic Ninja

Comments

Marian Pop

PHP / Laravel Developer. Writing and maintaining @LaravelMagazine. Host of "The Laravel Magazine Podcast". Pronouns: vi/vim.

Subscribe to our newsletter

Get latest news, tutorials, community articles and podcast episodes delivered to your inbox.

Weekly articles
We send a new issue of the newsletter every week on Friday.
No spam
We'll never share your email address and you can opt out at any time.