<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pintu Kumar on Medium]]></title>
        <description><![CDATA[Stories by Pintu Kumar on Medium]]></description>
        <link>https://medium.com/@er-pkumar?source=rss-5a9e6e571a25------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*b-wj2VfSkPXTAVGJWcWi9w.jpeg</url>
            <title>Stories by Pintu Kumar on Medium</title>
            <link>https://medium.com/@er-pkumar?source=rss-5a9e6e571a25------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 08:03:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@er-pkumar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Takeaways from Laracon US 2024: Chaperone, Deferred Functions and Cache::Flexible]]></title>
            <link>https://medium.com/@er-pkumar/takeaways-from-laracon-us-2024-chaperone-deferred-functions-and-cache-flexible-c67b5981e9dd?source=rss-5a9e6e571a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/c67b5981e9dd</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Pintu Kumar]]></dc:creator>
            <pubDate>Mon, 16 Sep 2024 05:35:25 GMT</pubDate>
            <atom:updated>2024-09-16T05:37:13.300Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bvb3xSjIa94X9EOfssllrA.png" /></figure><p><a href="https://github.com/taylorotwell">Taylor Otwell</a> contributed all of the goodies he shared in his <a href="https://laravel-news.com/laravel-laracon-us-keynote-2024">Laracon US 2024 keynote</a>, including chaperone(), defer(), Cache::flexible(), contextual container attributes, and more.</p><p>Here we will see each of these three highlights with examples and use cases.</p><p><strong>chaperone(): </strong>The chaperone() 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).</p><p><strong>Before</strong> the introduction of the chaperone() method, the comments() relationship in a Laravel model would have looked like a typical hasMany() relationship, without any additional authorization or permission checks. Here&#39;s how it would appear:</p><pre>public function comments(): HasMany<br>{<br>    return $this-&gt;hasMany(Comment::class);<br>}</pre><p>With chaperone(), when you add .chaperone(&#39;post&#39;):</p><ul><li>The chaperone() method introduces a layer of authorization to the relationship. It ensures that only authorized users (based on the permissions or roles defined) can access or interact with the comments relationship.</li><li>&#39;post&#39; is likely a reference to a permission or role context that Chaperone uses to determine if the current user can perform actions related to the comments on this Post.</li></ul><pre>public function comments(): HasMany<br>{<br>    return $this-&gt;hasMany(Comment::class)-&gt;chaperone(&#39;post&#39;);<br>}</pre><p>In summary, before chaperone(), the comments() relationship was purely about data retrieval with no built-in access control. After chaperone(), authorization rules are applied, restricting access based on defined roles or permissions.</p><p><strong>For more depth knowledge visit this link:</strong> <a href="https://www.youtube.com/watch?v=bDa2X6_H0kU">Laravel Chaperone Method</a></p><p><strong>Helpers: Deferred Functions</strong></p><p>In Laravel, you can use queued jobs to handle background tasks, but sometimes you might have small tasks that you want to delay without setting up and managing a full queue system.</p><p>This is where deferred functions come in. They let you postpone a task until after the user has received the HTTP response, keeping your app quick and responsive. To use a deferred function, just pass the task (as a closure) to the defer function, and it will handle the rest.</p><pre>use App\Services\Metrics;<br>use Illuminate\Http\Request;<br>use Illuminate\Support\Facades\Route;<br> <br>Route::post(&#39;/orders&#39;, function (Request $request) {<br>    // Create order...<br> <br>    defer(fn () =&gt; Metrics::reportOrder($order));<br> <br>    return $order;<br>});</pre><p>Deferred functions only run if the HTTP response, Artisan command, or queued job completes successfully. They won’t execute if a 4xx or 5xx error occurs. To ensure a deferred function always runs, you can chain the always method onto it.</p><pre>defer(fn () =&gt; Metrics::reportOrder($order))-&gt;always();</pre><p><strong>Cache::flexible()</strong></p><p>In Laravel, Cache::Flexible is a caching mechanism that allows you to cache data with a flexible expiration time. It’s a powerful tool for improving application performance by storing frequently accessed data and reducing the load on your database or external APIs.</p><p><strong>How it works</strong></p><p>Cache::Flexible uses a tuple to store the cached data, consisting of:</p><ol><li>Key: A unique identifier for the cached data.</li><li>Expiration time: A timestamp indicating when the cached data should be considered stale.</li><li>Value: The actual data being cached.</li></ol><p>When you use Cache::Flexible, Laravel will store the data in the cache with the specified expiration time. If the data is requested again before the expiration time, Laravel will return the cached value immediately. If the expiration time has passed, Laravel will recalculate the value and store it in the cache again.</p><p>Here’s an example of how to use Cache::Flexible:</p><pre>$value = Cache::flexible(&#39;user_data&#39;, [5, 10], function () {<br>    // Calculate user data (e.g., fetch from database)<br>    return User::find(1)-&gt;toArray();<br>});</pre><p><strong>In this example:</strong></p><ul><li>user_data is the key for the cached data.</li><li>[5, 10] specifies the expiration time tuple:</li></ul><blockquote>5 is the “fresh” time, indicating how long the cache should be considered fresh (in seconds).</blockquote><blockquote>10 is the “stale” time, indicating how long the cache should be considered stale (in seconds).</blockquote><ul><li>The closure function calculates the user data and returns it as an array.</li></ul><p><strong>Benefits:</strong></p><p><strong>Improved performance:</strong> By caching frequently accessed data, you reduce the load on your database or external APIs.</p><p><strong>Flexible expiration:</strong> You can set custom expiration times for each cached item, allowing you to balance performance and data freshness.</p><p><strong>Automatic invalidation:</strong> When the expiration time passes, Laravel will automatically recalculate the value and update the cache.</p><p>For more details update on The Laracon US 2024 keynotes by Taylor Ottwel, please visit official link here:</p><p><a href="https://laravel-news.com/laravel-laracon-us-keynote-2024">The Laracon US 2024 Keynote by Taylor Otwell is Now Available - Laravel News</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c67b5981e9dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Do +, #, and — Mean in UML? Attribute Access Levels Explained(Laravel)]]></title>
            <link>https://medium.com/@er-pkumar/what-do-and-mean-in-uml-attribute-access-levels-explained-laravel-9c433125a609?source=rss-5a9e6e571a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c433125a609</guid>
            <category><![CDATA[visibility-modifier]]></category>
            <category><![CDATA[object-oriented-design]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[developer-guide]]></category>
            <category><![CDATA[uml]]></category>
            <dc:creator><![CDATA[Pintu Kumar]]></dc:creator>
            <pubDate>Tue, 10 Sep 2024 05:41:07 GMT</pubDate>
            <atom:updated>2024-09-10T05:41:07.998Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Do +, #, and — Mean in UML? Attribute Access Levels Explained(Laravel)</h3><p>In Laravel, you can use debug helper functions such as decodeResponseJson() when debugging tests. It is likely a custom method used to decode HTTP responses, such as decoding JSON responses from an API call.</p><p>Let’s take a look at the notation used here. I am sharing some sample data with the corresponding notation:</p><figure><img alt="sample response with UML notation." src="https://cdn-images-1.medium.com/max/483/1*GXG1YBzUS8T-xBwCBOupKw.png" /><figcaption>Sample data</figcaption></figure><p>You may have noticed the +, #, and — symbols next to each data attribute. Do you know what these notations mean? If not, you’re in the right place! These symbols represent UML notation for attribute visibility.</p><p><strong><em>UML</em></strong> notation is a standardized visual language used to represent the structure and behavior of a system, including its classes, objects, relationships, and interactions.</p><p>Detailed of each notation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*OpOX8wrJZNfcIFaWt_vvZg.png" /><figcaption>UML notation explanation</figcaption></figure><p>These symbols specify the level of access for the attribute/method:</p><ul><li><strong>Public</strong> (+) allows access from anywhere.</li><li><strong>Protected</strong> (#) limits access to the class itself and its sub-classes.</li><li><strong>Private</strong> (-) restricts access to within the class only.</li></ul><p>#UML #ObjectOrientedDesign #SoftwareDevelopment #UMLNotation #PublicProtectedPrivate #CodingTips #VisibilityModifiers #LearnUML #DeveloperGuide</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c433125a609" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>