Artisan `make` Commands Automatically Chop `.php` Extension in Laravel 11.12

This week, the Laravel team released v11.12, which includes a multiply collection method, automatically chopping the .php extension in make commands, and more.

Chop PHP Extension When Passed to make Commands (v11.11.1)

Jason McCreary contributed a nice DX feature when passing .php to make:* commands for generating files for things like controllers, events, commands, etc. Nothing changes except that Laravel now handles the .php extension behind the scenes:

php artisan make:controller UserController.php
# Before - app/Http/Controllers/UserController.php.php
# After - app/Http/Controllers/UserController.php

It's painful when you accidentally do this because you have to either move the files or delete them and recreate everything. It's not clear if the command will take care of chopping the extension when typing, so this is a nice touch to some hidden pain—at least for me ;)

Add multiply() Method to Collections

<iframe width="1185" height="667" src="https://www.youtube.com/embed/AWvXjUnUdw8" title="Laravel collections now include a "multiply" method" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

Patrick O'Meara contributed a multiply() method to collections, which multiplies the items in the collection. It works by multiplying the existing values on the collection x number of times:

$c = collect([
    ['name' => 'User #1', 'email' => 'user1@example.com'],
    ['name' => 'User #2', 'email' => 'user2@example.com'],
])->multiply(2);

The collection above would look as follows after calling multiply(2):

Add Event Discovery Paths to the Event Service Provider

@Jascha contributed a addEventDiscoveryPaths() method to the event service provider if you need to add additional event discovery paths dynamically. This feature isn't typically needed, but you can do so with:

use Illuminate\Foundation\Support\Providers\EventServiceProvider;

EventServiceProvider::addEventDiscoveryPaths('/some/path/to/events');
EventServiceProvider::addEventDiscoveryPaths([
    '/some/path',
    '/another/path'
]);

Release notes

You can see the complete list of new features and updates below and the diff between 11.11.0 and 11.12.0 on GitHub. The following release notes are directly from the changelog:

v11.12.0

v11.11.1


The post Artisan `make` Commands Automatically Chop `.php` Extension in Laravel 11.12 appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.