CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

04 September, 2024

Chaperone Eloquent Models in Laravel 11.22

 Programing Coderfunda     September 04, 2024     No comments   

---




The Laravel team released v11.22 this week, with the chaperone() Eloquent method for inverse relations, support for passing backed Enums to Queuable methods, the ability to pass backed Enums to route ->name() and ->domain() methods, and more.


Chaperone Eloquent Relations




Samuel Levy contributed the Eloquent inverse/chaperone model relation that Taylor demonstrated in his 2024 Larcon US keynote during the open-source part of the talk.
public function comments(): HasMany
{
return $this->hasMany(Comment::class)->chaperone('post');
}



The chaperone()/inverse() method avoids unexpected N+1 queries by linking back to the parent after the relationship query has run. The above relationship will link the appropriate Post model in the correct relation on Comment instances (with scopes intact).


See Pull Request #51582 for more details.


Support Backed Enum in the Queueable Trait




Seth Phat contributed support for BackedEnum in Queuable trait methods:




*
onQueue()


*
onConnection()


*
allOnQueue()


*
allOnConnection()






Here's an example from the pull request:
use App\Enums\QueueConnection;
use App\Enums\QueueName;

// Before
public function register()
{
$user = User::create([...]);

SendWelcomeEmailJob::dispatch($user)
->withConnection(QueueConnection::REDIS->value)
->onQueue(QueueName::HIGH->value);
}

// After
public function register()
{
$user = User::create([...]);

SendWelcomeEmailJob::dispatch($user)
->withConnection(QueueConnection::REDIS)
->onQueue(QueueName::HIGH);
}



Allow Enums to be Passed to Routes




@NickSdot contributed passing BackedEnum to Route domain() and name() methods:
// Before
Route::domain(InterfaceDomain::Marketing->value)
->name(Routes::Home->value)
->get('/contact', ContactController::class);

// After
Route::domain(InterfaceDomain::Marketing)
->name(Routes::Home)
->get('/'contact, ContactController::class);



Release notes




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


v11.22.0






* [11.x] Fix FoundationServiceProvider docblock by @seriquynh in
https://github.com/laravel/framework/pull/52542 />

* [11.x] Fix ReflectionParameter @param type on Util::getContextualAttributeFromDependency() by @samsonasik in
https://github.com/laravel/framework/pull/52541 />

* [11.x] More specific parameter type in CastsInboundAttributes by @lorenzolosa in
https://github.com/laravel/framework/pull/52536 />

* [11.x] Unify prefetch API by @timacdonald in
https://github.com/laravel/framework/pull/52550 />

* [11.x] Add PDO subclass support for PHP 8.4 by @ju5t in
https://github.com/laravel/framework/pull/52538 />

* [11.x] Handle circular references in model serialization by @samlev in
https://github.com/laravel/framework/pull/52461 />

* [11.x] Eloquent inverse relations by @samlev in
https://github.com/laravel/framework/pull/51582 />

* [11.x] Feature/whereany closures by @liamduckett in
https://github.com/laravel/framework/pull/52555 />

* [11.x] Update remaining workflows to run on latest possible ubuntu version by @Jubeki in
https://github.com/laravel/framework/pull/52566 />

* Correct comments to better represent the updated method functionality by @dropweb in
https://github.com/laravel/framework/pull/52564 />

* [11.x] Support CSP nonce by @timacdonald in
https://github.com/laravel/framework/pull/52558 />

* [11.x] Allow enums to be passed to routes by @NickSdot in
https://github.com/laravel/framework/pull/52561 />

* [11.x] SORT_NATURAL on Collection no longer throws warning for nulls by @Chaplinski in
https://github.com/laravel/framework/pull/52557 />

* [11.x] Allow prefetch to start on custom event by @timacdonald in
https://github.com/laravel/framework/pull/52574 />

* [11.x] Fix regression in database assertions with custom model connections by @devfrey in
https://github.com/laravel/framework/pull/52581 />

* [11] Update DetectsLostConnections.php by @webartisan10 in
https://github.com/laravel/framework/pull/52614 />

* Fix docblock for Model::getEventDispatcher() by @inmula in
https://github.com/laravel/framework/pull/52602 />

* [11.x] Restore Request::HEADER_X_FORWARDED_PREFIX in TrustProxies by @taka-oyama in
https://github.com/laravel/framework/pull/52598 />

* [11.x] Accepts BackedEnum for onQueue, onConnection, allOnQueue, and allOnConnection methods in the Queueable trait by @sethsandaru in
https://github.com/laravel/framework/pull/52604 />

* [11.x] Use the same parameter type for 'throwUnless' as used for 'throwIf' by @pataar in
https://github.com/laravel/framework/pull/52626 />

* [11.x] Pass iterable keys to withProgressBar in InteractsWithIO by @robinmoisson in
https://github.com/laravel/framework/pull/52623 />

* [11.x] Fix docblock for Filesystem::hash() by @sunaoka in
https://github.com/laravel/framework/pull/52630 />

* Fix Apostrophe Handling in SeeInOrder.php and Enhance Test Coverage by @nomitoor in
https://github.com/laravel/framework/pull/52627 />

* [11.x] SQLite Error: "General error: 1 no such table" after adding a foreign key when using a table prefix. by @incrize in
https://github.com/laravel/framework/pull/52578 />






The post Chaperone Eloquent Models in Laravel 11.22 appeared first on Laravel News.


Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook

Related Posts:

  • Magento 2 Routing Magento 2 RoutingIn this article, we will talk about an important part in Magento 2 Routing. The Route will define name for a module which we ca… Read More
  • Magento 2 Plugin - Interceptor Magento 2 Plugin - InterceptorMagento 2 Plugin is a technical plugin for your better writing code. Interception Plugin is referred to a lit… Read More
  • Magento 2 Indexing & Reindex Magento 2 Indexing & ReindexIn this article we will learn how to create an magento 2 indexing, magento 2 reindex. Indexer is an important fe… Read More
  • Magento 2 EventsMagento 2 EventsThis article will talk about Event in Magento 2. As you know, Magento 2 is using the event driven architecture which will help too muc… Read More
  • How to customize a checkout step in Magento 2How to edit the custom style of checkout stepCustomize the style of a checkout step means removing , disabling or adding a component in the … Read More
Newer Post Older Post Home

0 comments:

Post a Comment

Thanks

Meta

Popular Posts

  • Vue3 :style backgroundImage not working with require
    I'm trying to migrate a Vue 2 project to Vue 3. In Vue 2 I used v-bind style as follow: In Vue 3 this doesn't work... I tried a...
  • SQL ORDER BY Keyword
      The SQL ORDER BY Keyword The ORDER BY keyword is used to sort the result-set in ascending or descending order. The ORDER BY keyword sorts ...
  • Enabling authentication in swagger
    I created a asp.net core empty project running on .net6. I am coming across an issue when I am trying to enable authentication in swagger. S...
  • failed to load storage framework cache laravel excel
       User the export file and controller function  ..         libxml_use_internal_errors ( true ); ..Good To Go   public function view () : ...
  • Features CodeIgniter
    Features CodeIgniter There is a great demand for the CodeIgniter framework in PHP developers because of its features and multiple advan...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh - 9/21/2024
  • pyspark XPath Query Returns Lists Omitting Missing Values Instead of Including None - 9/20/2024
  • SQL REPL from within Python/Sqlalchemy/Psychopg2 - 9/20/2024
  • MySql Explain with Tobias Petry - 9/20/2024
  • How to combine information from different devices into one common abstract virtual disk? [closed] - 9/20/2024

Laravel News

  • Cast Model Properties to a Uri Instance in 12.17 - 6/4/2025
  • Simplify Negative Relation Queries with Laravel's whereDoesntHaveRelation Methods - 5/31/2025
  • Efficiently remove expired cache data with Laravel Cache Evict - 6/3/2025
  • Test Job Failures Precisely with Laravel's assertFailedWith Method - 5/31/2025
  • Prism Relay - 6/2/2025

Copyright © 2025 CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda