Laravel 8.41, weekly updates, and 🔥 tip

Laravel 8.41

We have two weeks worth of changes today which bumps us up another minor version to 8.41. Since there are so many changes, I'm going to highlight the additions:

  • Add withOnly method in #37144
  • Allow adding more jobs to a pending batch in #37151
  • Add fallback when migration is not anonymous class in #37166
  • Add updateQuietly to update model without raising events in #37169
  • Add cursor pagination via cursorPaginate in #37216 and #37315
  • Add support for mass assignment to SQL Server views in #37307
  • Add unless to stringable in #37326
  • Add model key extraction to whereKey and whereKeyNot in #37184

You may review the full branch diff on GitHub for a complete list of changes.

This minor version bump and update is automated for subscribers to a Shifty Plan. If you don't have one of those, be sure to bump your constraint and run composer update to get the latest features.

Weekly Journal

Last week I worked on a few Human Shifts as well as some coaching sessions. Afterwards I tweaked some of the Shifts I ran to improve their automation.

One tweak was automatically creating the migration for the failed_jobs table in Laravel 8. This was something that was originally a comment on the PR, but could be improved by checking for the existing of the default failed_jobs table migration and adding it.

I want to automate some additional changes in the Laravel 8.x Shift. But I am waiting until the release of Laravel 9 to confirm these conventions are here to stay and more widely adopted.

Jess was on vacation last week, so we didn't get to pair. I continued working on the secret project solo. Fortunately we were able to pair this morning. Jess showed me a bit of UI she added which I think puts us very close to an alpha release.

I plan to demo it to a few of the "Laravel Elite" later in the week to get some initial feedback. If everything goes well, we will release a public alpha by the end of the month.

🔥 Tip

Something I shared before but still notice in a lot of projects is the presence of an app/helpers.php file. I recommend putting this under the bootstrap folder instead. I consider this code something the application requires to run (needs to be bootstrapped), but is not "class based" code.

To that point, Composer 2 actually does a better job of warning about files which may not be autoloaded properly. You've probably noticed a bunch of these in the output of composer install for packages not compliant with the PSR-4 standard.

In Laravel, the app folder is autoloaded using PSR-4. So it does not automatically load files which do not contain classes. And if it does, you'd likely receive the warning from Composer.

So if your application has an app/helpers.php file, consider moving it to the bootstrap folder with the following command:

1git mv app/helpers.php bootstrap/

And update your composer.json file to properly autoload it as an individual file:

1"autoload": {
2 "files": [
3 "bootstrap/helpers.php"
4 ]
5}

If you have classes within your helpers.php file, you should split these out into individual classes stored under app/Helpers and namespace them with App\Helpers to comply with the PSR-4 autoloading requirements.