The essential news about content management systems and mobile technology. Powered by Perfect Publisher and XT Search for Algolia.
The News Site publishes posts to the following channels: Facebook, Instagram, Twitter, Telegram, Web Push, Tumblr, and Blogger.
The pest-plugin-route-testing for Pest helps
you ensure your routes are okay in Laravel. This package has useful
methods to filter down which routes to run, bind users to test
routes, and more. The simplest example is testing all
GET
routes, which you can do with one method call:
use function Spatie\RouteTesting\routeTesting;
routeTesting('all GET routes')
->assertSuccessful();
All your application routes have high-level validation that
returns a 200
status code. That's pretty neat!
include()
methodexclude()
methodHere are a few more examples from the project's readme, illustrating how to use this plugin:
use function Spatie\RouteTesting\routeTesting;
// Filter routes to include
routeTesting('all blog routes')
->include('blog*', 'post*')
->assertSuccessful();
// Exclude some routes
routeTesting('all blog routes')
->exclude('admin*')
->assertSuccessful();
// Bind a user to test all routes
use App\Models\User;
routeTesting('all blog routes')
->bind('user', User::factory()->create())
->assertSuccessful();
// Run some code before
routeTesting('all admin routes')
->setUp(function ()
{
$user = User::factory()->create();
$this->actingAs($user);
// optionally, you could also bind the model
$this->bind('user', $user);
})
->include('admin*')
->assertSuccessful();
You can get started with this package on GitHub at spatie/pest-plugin-route-testing. To install it in your project, add it as a Composer dependency:
composer require spatie/pest-plugin-route-testing
The post Pest Route Testing Plugin for Laravel Applications appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/pest-route-testing-plugin
The Laravel team released v11.26 this week, with the ability to gracefully stop a pool of processes, using Enums when defining Rate Limiting, an Artisan command to make Job Middleware and more.
Seth Phat contributed using BackedEnum
and UnitEnum
to register a rate limiter:
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for(
GlobalRateLimit::HUBSPOT,
fn () => Limit::perSecond(100, 10)
);
You can also use them with the RateLimited
queue
job middleware:
use Illuminate\Queue\Middleware\RateLimited;
public function middleware(): array
{
return [
new RateLimited(GlobalRateLimit::HUBSPOT)
];
}
make:job-middleware
Artisan CommandDavey Shafik contributed a
make:job-middleware
Artisan command to create new job
middleware in the App\Jobs\Middleware
namespace:
php artisan make:job-middleware RateLimited
Mathias Hansen contributed an update to stop all processes in a pool gracefully that are running:
//
// Single process example
//
$process = Process::timeout(120)->start('bash import.sh');
// ...
$process->stop();
//
// Pool example
//
$this->pool = Process::pool(function (Pool $pool) {
$pool->path(base_path())->command('sleep 5');
$pool->path(base_path())->command('sleep 10');
})->start();
// Stop the processes gracefully
$this->pool->stop();
// Stop the processes with a specific signal
$this->pool->stop($signal);
make:model
Punyapal Shah contributed an update to the
make:model
command that will include a generic
annotation for the HasFactory
trait. This will help
IDEs understand the factory type returned for a given
Model::factory()
call.
Before Laravel 11.26, the stub would generate the following:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use HasFactory;
}
With the release of Laravel 11.26:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
/** @use HasFactory<\Database\Factories\PostFactory> */
use HasFactory;
}
You can see the complete list of new features and updates below and the diff between 11.25.0 and 11.26.0 on GitHub. The following release notes are directly from the changelog:
Enumerable::implode()
by @devfrey in
https://github.com/laravel/framework/pull/52937RateLimiter
& RateLimited
middleware by
@sethsandaru in https://github.com/laravel/framework/pull/52935REMOTE_ADDR
not working
in Swoole by @chuoke in https://github.com/laravel/framework/pull/52889[@include](https://github.com/include)('vendor/autoload.php')
via Laravel Envoy by @s-damian in
https://github.com/laravel/framework/pull/52974make:job-middleware
artisan command by
@dshafik in https://github.com/laravel/framework/pull/52965The post Laravel 11.26 Released appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/laravel-11-26-0
Version 5.0 of the official Laravel MongoDB integration is now available. This major update introduces breaking changes to better align the MongoDB integration with Laravel’s conventions and behaviors, simplifying MongoDB usage for developers already familiar with Eloquent.
id
to _id
in MongoDB is now supported,
eliminating the need for specifying protected $primaryKey =
'_id'
in model classes, simplifying the code. Replace
$model->_id
with $model->id
in your
code.DateTimeInterface
objects, including Carbon, are now
automatically converted to MongoDB’s UTCDateTime
for
insert and update operations. Similarly, when retrieving data,
MongoDB’s UTCDateTime
is automatically converted back
into Carbon date with the default timezone. This change simplifies
working with dates in MongoDB, reducing the need for custom
Eloquent casts.stdClass
objects instead of
arrays. The object properties can now be accessed using
$item->name
rather than
$item['name']
.$collection
has been replaced by $table
for customizing the collection name in Eloquent models, aligning
with Laravel convention.Auth\PasswordResetServiceProvider
,
MongoDBQueueServiceProvider
, and
Queue\Failed\MongoFailedJobProvider
. These providers
are no longer necessary, as MongoDB\Connection
is now
fully compatible with Laravel’s classes.MongoDB\Laravel\Connection
has been replaced with
MongoDB\Connection
, and the query logging now uses
MongoDB Monitoring Events.Refer to the upgrade guide to handle the breaking changes.
The post Laravel MongoDB releases version 5.0 appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/laravel-mongodb-5-0
Welcome to the first edition of the Laravel Roundup. At the beginning of each month, we plan to create a post highlighting the latest news, jobs, and community-related items.
Laravel raises a $57 million Series A from
Accel
Partnering with Accel has allowed Laravel to start building a
world-class engineering and leadership team, which has resulted in
Laravel Cloud and another product that will be
announced at Laracon AU in November.
Pinkary is now fully open source
Nuno Maduro announced at Laracon that Pinkary is now fully open
source.
New Laravel Creator Spotlight Interview
Series
We started a new interview video series on our YouTube channel to
highlight people creating things within the community.
PHP 8.4 RC1 is out
The PHP team announced the release of the first PHP 8.4 release
candidate!
Laravel Releases
Laravel continues its weekly release schedule, and many handy new
features have been added recently. Check our releases page for info
on each new one.
Pest 3 is released
The Pest team released Pest 3. Get started with mutation testing
today and level up your existing projects by finding untested
code.
If you want to hire Laravel developers, visit LaraJobs and see your job listing here next month.
Ashley Allen covers some of his favorite tips for working with Laravel models.
Learn how to create custom Facades in Laravel
If Facades have ever confused you as someone new to Laravel, come along with Paul Redmond and learn how to identify the service behind ANY Facade you might see in the framework.
How to Build Your First PHP Package
If you're new to PHP and want to create a PHP package from scratch, let's dive in and see how it's done!
A Deep Dive into Sessions in Laravel
When building Laravel applications, it's almost guaranteed you'll need to deal with sessions at some point. They are a fundamental part of web development. This article will quickly cover what sessions are, how they work in Laravel, and how you can work with them in your Laravel applications.
Contact us if you have an upcoming Laravel meetup that you'd like to see listed.
We cover a lot of Laravel Packages here on Laravel News, and here are some of the recent most popular.
The post Laravel Roundup - October appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/laravel-roundup-october
Have you ever wanted to log specific levels in Laravel? Sure,
you can use the level
config option to specify the
minimum level to log, but what if you only want
Debug
and Info
logs to go in a specific
logger?
Let's say you are writing a CLI and want to split logging
between stdout
and stderr
. Using
something like Laravel Zero or Artisan, you might have the
following command to demonstrate sending only stderr logs
somewhere:
php artisan my-command 2> storage/logs/stderr.log
[2024-10-01 02:48:34] development.INFO: Daemon started.
[2024-10-01 02:48:34] development.INFO: The daemon has run 1 times.
[2024-10-01 02:48:37] development.INFO: The daemon has run 2 times.
[2024-10-01 02:48:40] development.INFO: The daemon has run 3 times.
[2024-10-01 02:48:43] development.INFO: The daemon has run 4 times.
And then the stderr logs might look something like the following:
[2024-10-01 02:48:49] development.ERROR: The daemon has run too many times. (6 times now, come on!)
[2024-10-01 02:48:52] development.ERROR: The daemon has run too many times. (7 times now, come on!)
[2024-10-01 02:48:55] development.ERROR: The daemon has run too many times. (8 times now, come on!)
[2024-10-01 02:48:58] development.ERROR: The daemon has run too many times. (9 times now, come on!)
[2024-10-01 02:49:01] development.ERROR: The daemon has run too many times. (10 times now, come on!)
[2024-10-01 02:49:04] development.ERROR: The daemon has run too many times. (11 times now, come on!)
[2024-10-01 02:49:07] development.ERROR: The daemon has run too many times. (12 times now, come on!)
[2024-10-01 02:49:10] development.ERROR: The daemon has run too many times. (13 times now, come on!)
[2024-10-01 02:49:13] development.ERROR: The daemon has run too many times. (14 times now, come on!)
The trick to configuring Laravel's logger to split logs is using Monolog's FilterHandler, which only lets records of a given level through the wrapped handler. A direct example might look as follows:
use Monolog\Handler\FilterHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
// Using minimum and maximum level parameters
$handler = new FilterHandler(
handler: new StreamHandler('php://stdout'),
minLevelOrList: Level::Debug,
maxLevel: Level::Info,
);
// Using a list
$handler = new FilterHandler(
handler: new StreamHandler('php://stdout'),
minLevelOrList: [Level::Debug, Level::Info]
);
I've used named arguments to help illustrate how we can
configure the FilterHandler in Laravel's logging.php
configuration file. We can change the stderr
and
stdout
log channels (or create new ones) with the
following configuration, using the stack
driver:
<?php
return [
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => explode(',', env('LOG_STACK', 'stdout,stderr')),
'ignore_exceptions' => false,
],
'stdout' => [
'driver' => 'monolog',
'handler' => \Monolog\Handler\FilterHandler::class,
'formatter' => env('LOG_STDOUT_FORMATTER'),
'with' => [
'handler' => fn () => new StreamHandler('php://stdout'),
'minLevelOrList' => [Monolog\Level::Debug, Monolog\Level::Info],
],
'processors' => [PsrLogMessageProcessor::class],
],
'stderr' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
'level' => 'notice',
'processors' => [PsrLogMessageProcessor::class],
],
],
];
Notice how the with
keys match the FilterLogger
constructor named arguments? The stdout
logger will
log the debug and info logs, while the stderr
logger
has the level
set to notice
to capture
any CLI errors of notice or above.
I'd also like to point out that Monolog accepts a Closure for
the FilterHandler
handler so that the wrapped
StreamHandler
instance is not created until the log
channel is used:
'handler' => fn () => new StreamHandler('php://stdout'),
Capturing logs in this manner is helpful in headless/daemon CLI
commands when we send logs from a container to a logging service.
For example, format error logs with JSON for consumption by a
service like DataDog. Here's an example of the environment settings
you might have, illustrated in a compose.yaml
file:
services:
cli:
build:
context: .
dockerfile: build/Dockerfile
# Do not output any messages to the console.
# Only logs will be sent.
command: ["daemon", "--quiet"]
environment:
LOG_CHANNEL: "stack"
LOG_LEVEL: "info"
LOG_STACK: "stdout,stderr"
LOG_STDOUT_FORMATTER: "\\Monolog\\Formatter\\JsonFormatter"
LOG_STDERR_FORMATTER: "\\Monolog\\Formatter\\JsonFormatter"
Monolog has many Handlers, Formatters, and Processors available
that you can configure in Laravel, and all of the common use-cases
are already covered in the logging.php
configuration
file.
You can learn more about logging in Laravel applications in the official documentation.
The post Split Log Levels Between Stdout and Stderr With Laravel appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/split-log-levels-between-stdout-and-stderr-with-laravel
Page 5 of 1359