The Laravel team released 8.14 with the ability to dispatch unique jobs, support for using sockets with schema:dump
, a route shortcut for alphanumeric parameters, and the latest new features, fixes, and changes in the 8.x branch. Let’s see what’s new in this release!
Paras Malhotra contributed the ability to dispatch unique jobs that are will not dispatch another job with the same key unless the job has completed processing. Here’s an example from the pull request showing how you can use it:
use Illuminate\Contracts\Queue\ShouldBeUnique;
class MyUniqueJob implements ShouldQueue, ShouldBeUnique
{
/**
* The number of seconds after which the job will no longer stay unique.
*
* @var int
*/
public $uniqueFor = 3600;
public function uniqueId()
{
return $this->user->id;
}
}
Illia Sakovich contributed an encryptUsing
model method to define an encrypted to be used with encrypted string casts. Here’s how you might use it to determine the encrypter used:
use Illuminate\Database\Eloquent\Model;
use Illuminate\Encryption\Encrypter;
$databaseEncryptionKey = config('database.encryption_key');
$encrypter = new Encrypter($databaseEncryptionKey);
Model::encryptUsing($encrypter);
Lito contributed support for using MySQL sockets with the schema:dump
command. Previously you could not dump a schema if MySQL only allows socket connections.
Amit Merchant contributed the whereAlphaNumeric
route expression constraint to define route constraints instead of directly using the regex conveniently. Here’s an example:
// Using `where()`
Route::get('user/{name}', function ($name) {
//
})->where('name', '[a-zA-Z0-9]+');
// New optional syntax
Route::get('user/{name}', function ($name) {
//
})->whereAlphaNumeric('name');
Laravel 8.13 introduced a few route parameter constraint shortcuts you might want to check out!
You can see the full list of new features and updates below and the diff between 8.13.0 and 8.14.0 on GitHub. The following release notes are directly from the changelog:
Model::encryptUsing()
(#35080)Illuminate\Routing\CreatesRegularExpressionRouteConstraints::whereAlphaNumeric()
(#35154)make:seeder
command name inside ModelMakeCommand (#35107)Illuminate\Database\Schema\Grammars\MySqlGrammar::typeTimestamp()
(#35143)The Original Article can be found on laravel-news.com
#laravel #php #web-development #programming #developer