Blade Component Slot Attributes in Laravel 8.56

Published on by

Blade Component Slot Attributes in Laravel 8.56 image

The Laravel team released 8.56 with a collections firstOrFail() method, Blade component slot attributes, default conditional validation rules, and the latest changes in the 8.x branch:

Validation Assertion Improvements

Dwight Watson contributed validation assertion improvements to assertInvalid that brings quality-of-life improvements:

// Generically assert there are errors
$response->assertInvalid();
 
// Array was required previously
// Now you can pass a string key
$response->assertInvalid(['name', 'email']);
 
$response->assertInvalid('email');

Blade Component Slot Attributes

Dan Harrin contributed the ability for blade component slots to have their own attributes:

<x-card class="shadow-sm">
<x-slot name="heading" class="font-bold">
Heading
</x-slot>
 
Content
 
<x-slot name="footer" class="text-sm">
Footer
</x-slot>
</x-card>

To learn more, check out the code and discussion in Pull Request #38372.

Collections "firstOrFail()" Method

@powellblyth contributed a firstOrFail() method to collections (and lazy collections) which makes things a little more fluent:

// Without `firstOrFail()`
$collection = new Collection([
['name' => 'foo'],
['name' => 'foo'],
['name' => 'bar'],
]);
 
// Slightly obscure code and hard to scan
if ($collection->where('name', 'fish')->count() === 0){
$collection->add('fish');
}
 
$this->doSomethingWith($collection);

Using firstOrFail() a missing value will throw an exception:

$collection = new Collection([
['name' => 'foo'],
['name' => 'foo'],
['name' => 'bar'],
]);
 
try {
$collection->where('name', 'fish')->firstOrFail()
}
// An Exception? This must be important, I'm glad I scanned it
catch (ItemNotFoundException){
// Ensure user has 'fish' in their collection
$collection->add('fish');
}
 
$this->doSomethingWith($collection);

Default Rules for Conditional Validation

@bastien-phi contributed default rules when a condition is false instead of having to write the inverse conditional rule:

return [
'email' => [
Rule::when($this->someComplexTest(), ['required']),
Rule::when(!$this->someComplexTest(), ['nullable']),
],
];

Now you can pass the default rule as the third argument:

return [
'email' => [
Rule::when(
$this->someComplexTest(),
['required'],
// When the condition is `false`...
['nullable']
),
],
];

Get Full Request URL Without Query Params

Ali Saleem contributed a fullUrlWithoutQuery() request method that allows you to remove specific parameters from the query string:

// Example: https://example.com/?color=red&shape=square&size=small
 
// Removes `color`
request()->fullUrlWithoutQuery('color');
// https://example.com/?shape=square&size=small
 
// Removes `color` and `size`
request()->fullUrlWithoutQuery(['color', 'size']);
// https://example.com/?shape=square

Release Notes

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

v8.56.0

Added

  • Added firstOrFail to Illuminate\Support\Collections and Illuminate\Support\LazyCollections (#38420)
  • Support route caching with trashed bindings (c3ec2f2)
  • Allow only keys directly on safe in FormRequest (5e4ded8)
  • Added default rules in conditional rules (#38450)
  • Added fullUrlWithoutQuery method to Request (#38482)
  • Added --implicit (and -i) option to make:rule (#38480)
  • Added colon port support in serve command host option (#38522)

Changed

  • Testing: Access component properties from the return value of $this->component() (#38396, 42a71fd)
  • Update InteractsWithInput::bearerToken() (#38426)
  • Minor improvements to validation assertions API (#38422)
  • Blade component slot attributes (#38372)
  • Convenient methods for rate limiting (2f93c49)
  • Run event:clear on optimize:clear (a61b24c2)
  • Remove unnecessary double MAC for AEAD ciphers (#38475)
  • Adds Response authorization to Form Requests (#38489)
  • Make TestResponse::getCookie public so it can be directly used in tests (#38524)
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