Create Controllers with a Custom Stub in Laravel 8.36

Published on by

Create Controllers with a Custom Stub in Laravel 8.36 image

The Laravel team released 8.36 with a custom stub option when creating controllers, a useCurrentOnUpdate method for blueprint datetime columns in MySQL, a dispatch_sync() helper function, and the latest changes in the 8.x branch:

Support useCurrentOnUpdate for MySQL Datetime Columns

Tim Martin contributed support for useCurrentOnUpdate for MySQL DATETIME column types:

This allows using DATETIME columns for metadata like created_at and updated_at more effectively. Since TIMESTAMP columns in MySQL suffer from the Year 2038 Problem , using DATETIME columns is preferred in some applications.

Here's an example from the tests:

$blueprint = new Blueprint('users');
$blueprint->dateTime('foo')->useCurrentOnUpdate();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(1, $statements);
$this->assertSame('alter table `users` add `foo` datetime on update CURRENT_TIMESTAMP not null', $statements[0]);

Queue dispatch_sync() Helper

Dries Vints contributed a dispatch_sync() helper function as an alternative to dispatch_now(). The dispatchSync() method is the recommended way to do synchronous dispatching (immediately). See the synchronous dispatching documentation for further details.

Allow Skipping TransformRequests Middleware via Closure

Taylor Otwell contributed the ability to skip TrimStrings and ConvertEmptyStringsToNull middleware. The pull request describes how this helps Laravel packages like Livewire and Octane:

Currently, Livewire has to do some nasty hacking to skip these middleware on certain requests and the approach is not suitable for use with Octane. Adding this feature will allow Livewire and other libraries to register a callback with this base middleware during the framework's boot process to determine if the middleware should be skipped. That callback will receive the current request on each invocation.

Here are a few examples given in the pull request, but generally you'll not need this functionality in Laravel apps unless you're building very specific packages (i.e., Livewire) that need this advanced control:

TrimStrings::skipWhen(fn ($request) => shouldBeSkipped($request));
ConvertEmptyStringsToNull::skipWhen(fn ($request) => shouldBeSkipped($request));

Custom Stub Type When Creating Controllers

Brian Dillingham contributed a --type flag for the make:controller command to define custom stub types for controllers:

php artisan make:controller CustomController --type=custom

Which would look for /stubs/controller.custom.stub in the application when creating the file. Custom stubs are helpful if you want more control and less manual editing when creating new controllers in a project.

Unfinished Option to the queue:prune-batches Command

Dries Vints contributed a --unfinished option to the queue:prune-batches console command that accepts an integer of hours to retain incomplete batch data. With the --unfinished option, the command will prune finished batches and unfinished batches based on the batch creation date older than X hours.

String Repeat Method

Jona Löffler contributed a repeat() method for the Str and Stringable classes. Here's an example from the pull request tests:

$this->assertSame('aaaaa', Str::repeat('a', 5));
$this->assertSame('aaaaa', (string) $this->stringable('a')->repeat(5));

Release Notes

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

v8.36.0

Revert

Added

  • Added support useCurrentOnUpdate for MySQL datetime column types (#36817)
  • Added dispatch_sync() helper (#36835)
  • Allowing skipping TransformRequests middlewares via Closure (#36856)
  • Added type option to make controller command (#36853)
  • Added missing return $this to Illuminate\Support\Manager::forgetDrivers() (#36859)
  • Added unfinished option to PruneBatchesCommand (#36877)
  • Added a simple Str::repeat() helper function (#36887)

Fixed

  • Fixed getMultiple and increment / decrement on tagged cache (0d21194)
  • Implement proper return types in cache increment and decrement (#36836)
  • Fixed blade compiler regex issue (#36843, #36848)
  • Added missing temporary_url when creating flysystem (#36860)
  • Fixed PostgreSQL schema:dump when read/write hosts are arrays (#36881)

Changed

  • Improve the exception thrown when JSON encoding response contents fails in Response::setContent() (#36851, #36868)
  • Revert isDownForMaintenance function to use file_exists() (#36889)
Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Asymmetric Property Visibility in PHP 8.4 image

Asymmetric Property Visibility in PHP 8.4

Read article
Access Laravel Pulse Data as a JSON API image

Access Laravel Pulse Data as a JSON API

Read article
Laravel Forge adds Statamic Integration image

Laravel Forge adds Statamic Integration

Read article
Transform Data into Type-safe DTOs with this PHP Package image

Transform Data into Type-safe DTOs with this PHP Package

Read article
PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell image

PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell

Read article
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article