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 Laravel team released v11.20 this week, including a new
collection method, a deduplicate string method, the ability to use
Enums with AssertableJson
, and more.
collapseWithKeys
to
Collection
Jason McCreary contributed a
collapseWithKeys()
method to the
Illuminate\Support\Collection
class that collapses
nested arrays while preserving their keys:
$c = collect([[1 => 'a'], [3 => 'c'], [2 => 'b']]);
$c->collapseWithKeys();
/*
[
1 => "a",
3 => "c",
2 => "b",
]
*/
deduplicate
to stringsJason McCreary contributed a
deduplicate
string helper that replaces consecutive
occurrences of a character with a character:
Str::deduplicate('random double spaces'); // 'random double spaces'
Str::deduplicate('/some//odd/path//', '/'); // '/some/odd/path/'
(string) str('zondaaaa')->deduplicate('a'); // 'zonda'
Andrew Brown contributed the ability to define a
--path
flag when you need to create the view path in a
custom file location:
php artisan make:component Foo --path custom/path
By default, the make:component
command will
continue to use the resources/views/components
folder.
MixFileNotFoundException
Exception
ClassIhor Vereshchynskyi contributed a new
MixFileNotFoundException
class to handle missing Mix
files. This exception provides a more precise error-handling
mechanism when this exception gets thrown.
where
methodsPatrick O'Meara contributed the ability to use
Enums while using where*
methods with
AssertableJson
instances:
// Before
fn (AssertableJson $json) => $json->where('role', UserRole::Developer->value)
// After
fn (AssertableJson $json) => $json->where('role', UserRole::Developer)
Christoph Rumpel updated the
make:notification
command to prompt for creating an
optional markdown view when you don't provide any initial
input:
php artisan make:notification
You will get the following prompts to select a markdown view for your notification class:
stackContains()
and
hiddenStackContains()
Methods to Context Stacks@lessevv contributed the ability to check if a value (or hidden value) is contained in a context stack. Here are a few examples from Pull Request #52346:
// Normal
Context::push('foo', 'bar', 'lorem');
Context::stackContains('foo', 'bar'); // true
Context::stackContains('foo', 'lorem'); // true
Context::stackContains('foo', 'doesNotExist'); // false
// Hidden
Context::pushHidden('foo', 'bar', 'lorem');
Context::hiddenStackContains('foo', 'bar'); // true
Context::hiddenStackContains('foo', 'lorem'); // true
Context::hiddenStackContains('foo', 'doesNotExist'); // false
Günther Debrauwer contributed
assertNotDeleted
, assertNotFailed
, and
assertNotReleased
assertions to the queue that you can
use to assert the inverse of these methods:
use App\Jobs\ProcessPodcast;
$job = (new ProcessPodcast)->withFakeQueueInteractions();
$job->handle();
$job->assertNotDeleted();
$job->assertNotFailed();
$job->assertNotReleased();
Facade::isFake()
PublicCaleb White contributed an update to the
isFake()
method, making the visibility public:
use Illuminate\Support\Facades\Bus;
Bus::isFake(); // false
Bus::fake();
Bus::isFake(); // true
You can see the complete list of new features and updates below and the diff between 11.19.0 and 11.20.0 on GitHub. The following release notes are directly from the changelog:
whereNone
method by @einar-hansen in https://github.com/laravel/framework/pull/52351Lock->block
method by @RedmarBakker in https://github.com/laravel/framework/pull/52349Model::resolveRouteBindingQuery
by @sebj54 in
https://github.com/laravel/framework/pull/52339Factory::afterCreating
callable
argument type by @villfa in https://github.com/laravel/framework/pull/52335collapseWithKeys
to Collection
by
@jasonmccreary in https://github.com/laravel/framework/pull/52347assertNotDeleted
, assertNotFailed
, and
assertNotReleased
by @gdebrauwer in
https://github.com/laravel/framework/pull/52320deduplicate
to strings by @jasonmccreary in https://github.com/laravel/framework/pull/52350Facade::isFake()
public by
@calebdw in https://github.com/laravel/framework/pull/52357whenExistsLoaded
method to
conditionally include relationship existence attribute by @CodeWithKyrian in https://github.com/laravel/framework/pull/52295in()
and inHidden()
functions to Context Stacks by @lessevv in
https://github.com/laravel/framework/pull/52346Context::stackContains
with
Closures. by @timacdonald
in https://github.com/laravel/framework/pull/52381list
validation rule as array for
"size rules" in validation messages by @siarheipashkevich in https://github.com/laravel/framework/pull/52385The post A New String Helper, Assert Enums in AssertableJson, and more in Laravel 11.20 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-20-0
At WordPress.com, writing isn’t just a task. It’s how we think. Automattic is a globally distributed company, which means our work is almost always done asynchronously. For us, written communication is oxygen. But that communication is not built around email. Instead we use a homegrown internal blogging tool. Since every piece of our writing lives as a blog post that will stay published and searchable forever, we need to write clearly and succinctly.
The team at Jetpack AI started wondering if there was a writing tool that could help everyone at Automattic, from right inside the WordPress editor. Rather than search externally, we built one. And today we’re excited to share it with you. Say hello to Write Brief with AI from Jetpack.
Internally, we called this tool Breve—Latin for “brief.” It started as a hack week project and caught on across the entire company. In fact, we saw just how useful and beloved it quickly became and decided to release it into the world. Write Brief with AI is available for free (while in beta) for all WordPress.com plans and users.
Write Brief with AI works right within the WordPress editor, handling blocks, nested blocks, patterns, and more. It’s an editing tool built to streamline your writing process directly in your familiar workspace. Write, edit, blog, directly from WordPress.
Simply click the Jetpack icon on the top right of your screen, and Write Brief with AI will get to work based on what’s check or unchecked in the sidebar.
We’re constantly improving and refining our platform based on your feedback. Write Brief with AI is just one step in our journey to make writing with WordPress even better. We’re excited for you to join us in this new chapter. Try it out in the post or page editor today and let us know what you think. Or click below to learn more.
Learn moreFor this release, Write Brief with AI is available exclusively in English. We’re working hard to expand language support in future updates.
Read more https://wordpress.com/blog/2024/08/06/write-brief-with-ai/
The Laravel framework provides a bunch of helpful test traits
that make our lives easier, such as migrating databases, setting up
Faker, removing middleware, and more. When writing feature tests in
Laravel, the base TestCase
class inherits the
framework's TestCase class. In this class, is the base
setUp
template is called in PHPUnit:
protected function setUp(): void
{
$this->setUpTheTestEnvironment();
}
The setUpTheTestEnvironment()
method—found in the
TestCase
's InteractsWithTestCaseLifecycle trait—does a few
things:
Model
class event dispatcher
instanceThe part that I want to focus on is the setUpTraits() method, which recursively returns traits on the instance. This method includes some internal framework trait checks and calls methods on those traits if they're used:
if (isset($uses[RefreshDatabase::class])) {
$this->refreshDatabase();
}
if (isset($uses[DatabaseMigrations::class])) {
$this->runDatabaseMigrations();
}
// ... etc
At the end of the method, it loops through all the traits and checks for the existence of a setup/teardown method that matches the trait name:
foreach ($uses as $trait) {
if (method_exists($this, $method = 'setUp'.class_basename($trait))) {
$this->{$method}();
}
if (method_exists($this, $method = 'tearDown'.class_basename($trait))) {
$this->beforeApplicationDestroyed(fn () => $this->{$method}());
}
}
If you had a MyUsefulHelper
trait on a test class,
the method_exists check would look for these methods:
public function setUpMyUsefulHelper();
public function tearDownMyUsefulHelper();
What's neat about the trait setup methods is that you can avoid boilerplate code anywhere you want to use this trait in a test:
class MyTestCase
{
use MyUsefulHelper;
// This method is not needed if a `setUpMyUsefulHelper` method is defined.
- public function setUp: void
- {
- parent::setUp();
-
- $this->initMyUsefulHelper();
- }
}
If your application has useful helpers, setup code, etc., using these hooks can clean up your code, and you don't have to remember to manually initialize the trait's setup. For example, perhaps you have factory code in multiple tests that sets up users, permissions, and roles. Your setup code could be moved into a reusable trait that automatically sets everything up before each test.
Recently, I created a trait to interact with a Wiremock server that required some setup and
teardown logic, such as defining custom mocked request/response
pairs (and cleaning them up afterwards). I created an
InteractsWithWiremock
trait that automatically takes
care of set up and reset automatically using Laravel's automatic
setUp
hook.
I love finding small nuggets like this in the Laravel framework code!
The post Use Laravel's Built-in SetUp Hooks for Application Test Traits 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-test-case-trait-setup-hooks
The Active Sessions card for Laravel
Pulse shows your application's total number of sessions,
including Web and API users. Based on the
pulse.active_session_threshold
value, this card will
display interactive color-coded indicators in the card based on
these values.
This package includes the following main features with the initial release:
To get started with this package, you can install it via Composer:
composer require vcian/pulse-active-sessions
Then you can configure the threshold using the
pulse.php
config file:
return [
// ...
'active_session_threshold' => 100,
];
Finally, add the pulse_active_session
component to
the Pulse dashboard.blade.php
file:
<x-pulse>
<livewire:pulse_active_session cols='4' rows='2' />
{{-- ... --}}
</x-pulse>
You can learn more about this package, get full installation instructions, and view the source code on GitHub. To get started with Pulse, follow the setup guide in the Laravel Documentation.
The post Active Sessions Card for Laravel Pulse 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/active-sessions-card-for-laravel-pulse
You’ve probably seen it on social media and in headlines around the web in the last few years: the fediverse. But what is it, really? A Boba Fett theme park? A Kevin Federline production? Some sort of cheese pun? In this first episode of our new YouTube series, the Fediverse Files, designer, illustrator, and fediverse expert Doc Pop explains exactly what the fediverse is so that you can jump in today to start building community and sharing content.
To kickstart your efforts, we’re giving you 25% off your first year on a Creator or Entrepreneur plan.
Get 25% off todayRead more https://wordpress.com/blog/2024/08/02/what-is-the-fediverse/