Skip to content

Commit f908fe3

Browse files
authored
Prep Laravel v12 (#9495)
1 parent 474701c commit f908fe3

File tree

2 files changed

+13
-864
lines changed

2 files changed

+13
-864
lines changed

releases.md

+4-319
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- [Versioning Scheme](#versioning-scheme)
44
- [Support Policy](#support-policy)
5-
- [Laravel 11](#laravel-11)
5+
- [Laravel 12](#laravel-12)
66

77
<a name="versioning-scheme"></a>
88
## Versioning Scheme
@@ -46,322 +46,7 @@ For all Laravel releases, bug fixes are provided for 18 months and security fixe
4646

4747
(*) Supported PHP versions
4848

49-
<a name="laravel-11"></a>
50-
## Laravel 11
49+
<a name="laravel-12"></a>
50+
## Laravel 12
5151

52-
Laravel 11 continues the improvements made in Laravel 10.x by introducing a streamlined application structure, per-second rate limiting, health routing, graceful encryption key rotation, queue testing improvements, [Resend](https://resend.com) mail transport, Prompt validator integration, new Artisan commands, and more. In addition, Laravel Reverb, a first-party, scalable WebSocket server has been introduced to provide robust real-time capabilities to your applications.
53-
54-
<a name="php-8"></a>
55-
### PHP 8.2
56-
57-
Laravel 11.x requires a minimum PHP version of 8.2.
58-
59-
<a name="structure"></a>
60-
### Streamlined Application Structure
61-
62-
_Laravel's streamlined application structure was developed by [Taylor Otwell](https://github.com/taylorotwell) and [Nuno Maduro](https://github.com/nunomaduro)_.
63-
64-
Laravel 11 introduces a streamlined application structure for **new** Laravel applications, without requiring any changes to existing applications. The new application structure is intended to provide a leaner, more modern experience, while retaining many of the concepts that Laravel developers are already familiar with. Below we will discuss the highlights of Laravel's new application structure.
65-
66-
#### The Application Bootstrap File
67-
68-
The `bootstrap/app.php` file has been revitalized as a code-first application configuration file. From this file, you may now customize your application's routing, middleware, service providers, exception handling, and more. This file unifies a variety of high-level application behavior settings that were previously scattered throughout your application's file structure:
69-
70-
```php
71-
return Application::configure(basePath: dirname(__DIR__))
72-
->withRouting(
73-
web: __DIR__.'/../routes/web.php',
74-
commands: __DIR__.'/../routes/console.php',
75-
health: '/up',
76-
)
77-
->withMiddleware(function (Middleware $middleware) {
78-
//
79-
})
80-
->withExceptions(function (Exceptions $exceptions) {
81-
//
82-
})->create();
83-
```
84-
85-
<a name="service-providers"></a>
86-
#### Service Providers
87-
88-
Instead of the default Laravel application structure containing five service providers, Laravel 11 only includes a single `AppServiceProvider`. The functionality of the previous service providers has been incorporated into the `bootstrap/app.php`, is handled automatically by the framework, or may be placed in your application's `AppServiceProvider`.
89-
90-
For example, event discovery is now enabled by default, largely eliminating the need for manual registration of events and their listeners. However, if you do need to manually register events, you may simply do so in the `AppServiceProvider`. Similarly, route model bindings or authorization gates you may have previously registered in the `AuthServiceProvider` may also be registered in the `AppServiceProvider`.
91-
92-
<a name="opt-in-routing"></a>
93-
#### Opt-in API and Broadcast Routing
94-
95-
The `api.php` and `channels.php` route files are no longer present by default, as many applications do not require these files. Instead, they may be created using simple Artisan commands:
96-
97-
```shell
98-
php artisan install:api
99-
100-
php artisan install:broadcasting
101-
```
102-
103-
<a name="middleware"></a>
104-
#### Middleware
105-
106-
Previously, new Laravel applications included nine middleware. These middleware performed a variety of tasks such as authenticating requests, trimming input strings, and validating CSRF tokens.
107-
108-
In Laravel 11, these middleware have been moved into the framework itself, so that they do not add bulk to your application's structure. New methods for customizing the behavior of these middleware have been added to the framework and may be invoked from your application's `bootstrap/app.php` file:
109-
110-
```php
111-
->withMiddleware(function (Middleware $middleware) {
112-
$middleware->validateCsrfTokens(
113-
except: ['stripe/*']
114-
);
115-
116-
$middleware->web(append: [
117-
EnsureUserIsSubscribed::class,
118-
])
119-
})
120-
```
121-
122-
Since all middleware can be easily customized via your application's `bootstrap/app.php`, the need for a separate HTTP "kernel" class has been eliminated.
123-
124-
<a name="scheduling"></a>
125-
#### Scheduling
126-
127-
Using a new `Schedule` facade, scheduled tasks may now be defined directly in your application's `routes/console.php` file, eliminating the need for a separate console "kernel" class:
128-
129-
```php
130-
use Illuminate\Support\Facades\Schedule;
131-
132-
Schedule::command('emails:send')->daily();
133-
```
134-
135-
<a name="exception-handling"></a>
136-
#### Exception Handling
137-
138-
Like routing and middleware, exception handling can now be customized from your application's `bootstrap/app.php` file instead of a separate exception handler class, reducing the overall number of files included in a new Laravel application:
139-
140-
```php
141-
->withExceptions(function (Exceptions $exceptions) {
142-
$exceptions->dontReport(MissedFlightException::class);
143-
144-
$exceptions->report(function (InvalidOrderException $e) {
145-
// ...
146-
});
147-
})
148-
```
149-
150-
<a name="base-controller-class"></a>
151-
#### Base `Controller` Class
152-
153-
The base controller included in new Laravel applications has been simplified. It no longer extends Laravel's internal `Controller` class, and the `AuthorizesRequests` and `ValidatesRequests` traits have been removed, as they may be included in your application's individual controllers if desired:
154-
155-
<?php
156-
157-
namespace App\Http\Controllers;
158-
159-
abstract class Controller
160-
{
161-
//
162-
}
163-
164-
<a name="application-defaults"></a>
165-
#### Application Defaults
166-
167-
By default, new Laravel applications use SQLite for database storage, as well as the `database` driver for Laravel's session, cache, and queue. This allows you to begin building your application immediately after creating a new Laravel application, without being required to install additional software or create additional database migrations.
168-
169-
In addition, over time, the `database` drivers for these Laravel services have become robust enough for production usage in many application contexts; therefore, they provide a sensible, unified choice for both local and production applications.
170-
171-
<a name="reverb"></a>
172-
### Laravel Reverb
173-
174-
_Laravel Reverb was developed by [Joe Dixon](https://github.com/joedixon)_.
175-
176-
[Laravel Reverb](https://reverb.laravel.com) brings blazing-fast and scalable real-time WebSocket communication directly to your Laravel application, and provides seamless integration with Laravel’s existing suite of event broadcasting tools, such as Laravel Echo.
177-
178-
```shell
179-
php artisan reverb:start
180-
```
181-
182-
In addition, Reverb supports horizontal scaling via Redis's publish / subscribe capabilities, allowing you to distribute your WebSocket traffic across multiple backend Reverb servers all supporting a single, high-demand application.
183-
184-
For more information on Laravel Reverb, please consult the complete [Reverb documentation](/docs/{{version}}/reverb).
185-
186-
<a name="rate-limiting"></a>
187-
### Per-Second Rate Limiting
188-
189-
_Per-second rate limiting was contributed by [Tim MacDonald](https://github.com/timacdonald)_.
190-
191-
Laravel now supports "per-second" rate limiting for all rate limiters, including those for HTTP requests and queued jobs. Previously, Laravel's rate limiters were limited to "per-minute" granularity:
192-
193-
```php
194-
RateLimiter::for('invoices', function (Request $request) {
195-
return Limit::perSecond(1);
196-
});
197-
```
198-
199-
For more information on rate limiting in Laravel, check out the [rate limiting documentation](/docs/{{version}}/routing#rate-limiting).
200-
201-
<a name="health"></a>
202-
### Health Routing
203-
204-
_Health routing was contributed by [Taylor Otwell](https://github.com/taylorotwell)_.
205-
206-
New Laravel 11 applications include a `health` routing directive, which instructs Laravel to define a simple health-check endpoint that may be invoked by third-party application health monitoring services or orchestration systems like Kubernetes. By default, this route is served at `/up`:
207-
208-
```php
209-
->withRouting(
210-
web: __DIR__.'/../routes/web.php',
211-
commands: __DIR__.'/../routes/console.php',
212-
health: '/up',
213-
)
214-
```
215-
216-
When HTTP requests are made to this route, Laravel will also dispatch a `DiagnosingHealth` event, allowing you to perform additional health checks that are relevant to your application.
217-
218-
<a name="encryption"></a>
219-
### Graceful Encryption Key Rotation
220-
221-
_Graceful encryption key rotation was contributed by [Taylor Otwell](https://github.com/taylorotwell)_.
222-
223-
Since Laravel encrypts all cookies, including your application's session cookie, essentially every request to a Laravel application relies on encryption. However, because of this, rotating your application's encryption key would log all users out of your application. In addition, decrypting data that was encrypted by the previous encryption key becomes impossible.
224-
225-
Laravel 11 allows you to define your application's previous encryption keys as a comma-delimited list via the `APP_PREVIOUS_KEYS` environment variable.
226-
227-
When encrypting values, Laravel will always use the "current" encryption key, which is within the `APP_KEY` environment variable. When decrypting values, Laravel will first try the current key. If decryption fails using the current key, Laravel will try all previous keys until one of the keys is able to decrypt the value.
228-
229-
This approach to graceful decryption allows users to keep using your application uninterrupted even if your encryption key is rotated.
230-
231-
For more information on encryption in Laravel, check out the [encryption documentation](/docs/{{version}}/encryption).
232-
233-
<a name="prompt-validation"></a>
234-
### Prompt Validation
235-
236-
_Prompt validator integration was contributed by [Andrea Marco Sartori](https://github.com/cerbero90)_.
237-
238-
[Laravel Prompts](/docs/{{version}}/prompts) is a PHP package for adding beautiful and user-friendly forms to your command-line applications, with browser-like features including placeholder text and validation.
239-
240-
Laravel Prompts supports input validation via closures:
241-
242-
```php
243-
$name = text(
244-
label: 'What is your name?',
245-
validate: fn (string $value) => match (true) {
246-
strlen($value) < 3 => 'The name must be at least 3 characters.',
247-
strlen($value) > 255 => 'The name must not exceed 255 characters.',
248-
default => null
249-
}
250-
);
251-
```
252-
253-
However, this can become cumbersome when dealing with many inputs or complicated validation scenarios. Therefore, in Laravel 11, you may utilize the full power of Laravel's [validator](/docs/{{version}}/validation) when validating prompt inputs:
254-
255-
```php
256-
$name = text('What is your name?', validate: [
257-
'name' => 'required|min:3|max:255',
258-
]);
259-
```
260-
261-
<a name="queue-interaction-testing"></a>
262-
### Queue Interaction Testing
263-
264-
_Queue interaction testing was contributed by [Taylor Otwell](https://github.com/taylorotwell)_.
265-
266-
Previously, attempting to test that a queued job was released, deleted, or manually failed was cumbersome and required the definition of custom queue fakes and stubs. However, in Laravel 11, you may easily test for these queue interactions using the `withFakeQueueInteractions` method:
267-
268-
```php
269-
use App\Jobs\ProcessPodcast;
270-
271-
$job = (new ProcessPodcast)->withFakeQueueInteractions();
272-
273-
$job->handle();
274-
275-
$job->assertReleased(delay: 30);
276-
```
277-
278-
For more information on testing queued jobs, check out the [queue documentation](/docs/{{version}}/queues#testing).
279-
280-
<a name="new-artisan-commands"></a>
281-
### New Artisan Commands
282-
283-
_Class creation Artisan commands were contributed by [Taylor Otwell](https://github.com/taylorotwell)_.
284-
285-
New Artisan commands have been added to allow the quick creation of classes, enums, interfaces, and traits:
286-
287-
```shell
288-
php artisan make:class
289-
php artisan make:enum
290-
php artisan make:interface
291-
php artisan make:trait
292-
```
293-
294-
<a name="model-cast-improvements"></a>
295-
### Model Casts Improvements
296-
297-
_Model casts improvements were contributed by [Nuno Maduro](https://github.com/nunomaduro)_.
298-
299-
Laravel 11 supports defining your model's casts using a method instead of a property. This allows for streamlined, fluent cast definitions, especially when using casts with arguments:
300-
301-
/**
302-
* Get the attributes that should be cast.
303-
*
304-
* @return array<string, string>
305-
*/
306-
protected function casts(): array
307-
{
308-
return [
309-
'options' => AsCollection::using(OptionCollection::class),
310-
// AsEncryptedCollection::using(OptionCollection::class),
311-
// AsEnumArrayObject::using(OptionEnum::class),
312-
// AsEnumCollection::using(OptionEnum::class),
313-
];
314-
}
315-
316-
For more information on attribute casting, review the [Eloquent documentation](/docs/{{version}}/eloquent-mutators#attribute-casting).
317-
318-
<a name="the-once-function"></a>
319-
### The `once` Function
320-
321-
_The `once` helper was contributed by [Taylor Otwell](https://github.com/taylorotwell)_ and _[Nuno Maduro](https://github.com/nunomaduro)_.
322-
323-
The `once` helper function executes the given callback and caches the result in memory for the duration of the request. Any subsequent calls to the `once` function with the same callback will return the previously cached result:
324-
325-
function random(): int
326-
{
327-
return once(function () {
328-
return random_int(1, 1000);
329-
});
330-
}
331-
332-
random(); // 123
333-
random(); // 123 (cached result)
334-
random(); // 123 (cached result)
335-
336-
For more information on the `once` helper, check out the [helpers documentation](/docs/{{version}}/helpers#method-once).
337-
338-
<a name="database-performance"></a>
339-
### Improved Performance When Testing With In-Memory Databases
340-
341-
_Improved in-memory database testing performance was contributed by [Anders Jenbo](https://github.com/AJenbo)_
342-
343-
Laravel 11 offers a significant speed boost when using the `:memory:` SQLite database during testing. To accomplish this, Laravel now maintains a reference to PHP's PDO object and reuses it across connections, often cutting total test run time in half.
344-
345-
<a name="mariadb"></a>
346-
### Improved Support for MariaDB
347-
348-
_Improved support for MariaDB was contributed by [Jonas Staudenmeir](https://github.com/staudenmeir) and [Julius Kiekbusch](https://github.com/Jubeki)_
349-
350-
Laravel 11 includes improved support for MariaDB. In previous Laravel releases, you could use MariaDB via Laravel's MySQL driver. However, Laravel 11 now includes a dedicated MariaDB driver which provides better defaults for this database system.
351-
352-
For more information on Laravel's database drivers, check out the [database documentation](/docs/{{version}}/database).
353-
354-
<a name="inspecting-database"></a>
355-
### Inspecting Databases and Improved Schema Operations
356-
357-
_Improved schema operations and database inspection was contributed by [Hafez Divandari](https://github.com/hafezdivandari)_
358-
359-
Laravel 11 provides additional database schema operation and inspection methods, including the native modifying, renaming, and dropping of columns. Furthermore, advanced spatial types, non-default schema names, and native schema methods for manipulating tables, views, columns, indexes, and foreign keys are provided:
360-
361-
use Illuminate\Support\Facades\Schema;
362-
363-
$tables = Schema::getTables();
364-
$views = Schema::getViews();
365-
$columns = Schema::getColumns('users');
366-
$indexes = Schema::getIndexes('users');
367-
$foreignKeys = Schema::getForeignKeys('users');
52+
TBA...

0 commit comments

Comments
 (0)