<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sandro Jhuliano Cagara</title>
    <description>The latest articles on DEV Community by Sandro Jhuliano Cagara (@sandrocagara).</description>
    <link>https://dev.to/sandrocagara</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F449083%2Feab2ad7c-7e5a-4246-aaea-575a160a3bbb.jpg</url>
      <title>DEV Community: Sandro Jhuliano Cagara</title>
      <link>https://dev.to/sandrocagara</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sandrocagara"/>
    <language>en</language>
    <item>
      <title>What’s New in Laravel 11?</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Thu, 04 Apr 2024 03:35:47 +0000</pubDate>
      <link>https://dev.to/sandrocagara/whats-new-in-laravel-11-4ecm</link>
      <guid>https://dev.to/sandrocagara/whats-new-in-laravel-11-4ecm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Streamlined Directory Structure&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    -&amp;gt;withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    -&amp;gt;withMiddleware(function (Middleware $middleware) {
        //
    })
    -&amp;gt;withExceptions(function (Exceptions $exceptions) {
        //
    })-&amp;gt;create();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Laravel 11 simplifies its directory structure, reducing the initial complexity for developers. Notably, Kernel.php files have been removed, and middleware can now be directly added in the bootstrap/app.php file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Improved Routing Efficiency&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::prefix('user')-&amp;gt;group(function () {
    Route::get('/dashboard', function () {
        // Dashboard view
    });
    Route::get('/setting', function () {
        // Setting view
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You can now define route groups more succinctly, this might look familiar, but under the hood, Laravel 11 optimizes these routes, making your application a tad quicker. It’s like giving your routes a little caffeine boost!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Enhanced Eloquent ORM&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected $casts = [
    'is_active' =&amp;gt; 'boolean',
    'launch_date' =&amp;gt; 'datetime',
    'options' =&amp;gt; 'array',
    'custom_object' =&amp;gt; CustomClass::class,
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;There’s a new feature called “Eloquent Casts” that allows you to convert attributes to common data types or even your custom classes more smoothly. This is super handy for working with data transformations directly in your model.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Custom Casts in Laravel 11&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class OptionsCast implements CastsAttributes
{
    public function get($model, string $key, $value, array $attributes)
    {
        return new Options(json_decode($value, true));
    }

    public function set($model, string $key, $value, array $attributes)
    {
        return $value-&amp;gt;toArray();
    }
}

class User extends Model
{
    protected $casts = [
        'options' =&amp;gt; OptionsCast::class,
    ];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In this example, Options is a custom class we’ve defined to work with our user options. The OptionsCast class ensures that whenever we access the options attribute on a User model, it’s returned as a Options object, and when we set it, it’s automatically serialized into the appropriate JSON format for storage.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Laravel Scout Database Engine&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$blogs = Blog::search('Laravel 11')-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Laravel Scout, the driver-based full-text search solution for Eloquent, now includes a database engine out of the box. This is perfect for those who don’t need a heavy search engine like Algolia or Elasticsearch for smaller projects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Improved Authorization Responses&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Gate::define('update-post', function ($user, $post) {
    return $user-&amp;gt;id === $post-&amp;gt;user_id
                ? Response::allow()
                : Response::deny('You do not own this post.');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Laravel 11 introduces a more intuitive way to handle authorization responses. Now, when a policy or gate denies access, you can provide a custom error message directly. This small change allows for more descriptive feedback to users when they’re not allowed to perform certain actions, improving the overall user experience.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Tailwind CSS Pagination Views&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{ $posts-&amp;gt;links() }}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;For the front-end folks, Laravel 11 ships with Tailwind CSS pagination views out of the box. If you’re riding the Tailwind wave, you’ll appreciate this addition. No more wrestling with custom pagination styles unless you want to!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Queue Improvements&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function handle()
{
    // Your job logic here
}

public function failed(Throwable $exception)
{
    // Called when the job fails
}

public $tries = 1;
public $backoff = 30; // Delay in seconds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Imagine you have a job that needs to retry on failure but with a specific delay and up to a maximum number of attempts. this setup provides more control over job retries and handling failures, making your application more resilient.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;New Testing Features&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$response = $this-&amp;gt;get('/api/post');

$response-&amp;gt;assertJson(fn (AssertableJson $json) =&amp;gt;
    $json-&amp;gt;where('id', 1)
         -&amp;gt;where('title', 'Laravel 11')
         -&amp;gt;etc()
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Testing is an integral part of the development process, and Laravel 11 introduces new testing features that make it easier to ensure your application works as expected. One such feature is enhanced HTTP client assertions, which allow for more expressive and comprehensive tests for your external HTTP requests.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Blade Component Tags&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;x-alert type="error" :message="$message" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This new syntax for component tags not only improves readability but also streamlines the process of passing data to components.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Laravel 11: The &lt;code&gt;once&lt;/code&gt; Method&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$value = once(function () {
    return config('app.name');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The once method is a simple yet powerful tool for optimizing your application. It promotes cleaner, more efficient code by ensuring that expensive operations are not unnecessarily repeated. Plus, it’s incredibly easy to use and integrate into your existing Laravel projects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;New Dumpable Trait in Laravel 11&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Illuminate\Support\Traits\Dumpable;

class User extends Model
{
    use Dumpable;
}
...

$model = User::find(1);
$model-&amp;gt;dump();

...
$model-&amp;gt;dd();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The Dumpable trait allows you to easily dump and die (dd) or just dump (dump) the properties of any Eloquent model or any class that uses this trait, directly from the object itself. This is particularly useful when you want to quickly inspect the data structure of your models or any other objects during development without resorting to external debugging tools or verbose logging methods.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>eloquent</category>
      <category>webdev</category>
    </item>
    <item>
      <title>1880's 10MB USB flash drive</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Sat, 28 Oct 2023 16:45:00 +0000</pubDate>
      <link>https://dev.to/sandrocagara/1880s-10mb-usb-flash-drive-2mfh</link>
      <guid>https://dev.to/sandrocagara/1880s-10mb-usb-flash-drive-2mfh</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj6d2niefpm9xpwrwuick.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj6d2niefpm9xpwrwuick.jpg" alt="Image description" width="800" height="597"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Laravel 9 - use bindings in your raw queries</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Sat, 27 May 2023 03:59:48 +0000</pubDate>
      <link>https://dev.to/sandrocagara/laravel-9-use-bindings-in-your-raw-queries-3kdl</link>
      <guid>https://dev.to/sandrocagara/laravel-9-use-bindings-in-your-raw-queries-3kdl</guid>
      <description>&lt;p&gt;You can pass an array of bindings to most raw query methods to avoid SQL injection.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is vulnerable to SQL injection&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$fullname = request('full_name');

User::whereRaw("CONCAT(first_name, last_name) = $fullName")-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Use bindings&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User::whereRaw("CONCAT(first_name, last_name) = ?", [request('full_name')])-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>programming</category>
      <category>php</category>
      <category>backend</category>
    </item>
    <item>
      <title>Laravel: The useCurrent() &amp; useCurrentOnUpdate()</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Fri, 10 Mar 2023 14:33:31 +0000</pubDate>
      <link>https://dev.to/sandrocagara/laravel-tips-001-1oc3</link>
      <guid>https://dev.to/sandrocagara/laravel-tips-001-1oc3</guid>
      <description>&lt;p&gt;When using &lt;code&gt;timestamp()&lt;/code&gt; columns in Laravel Migrations, append the &lt;code&gt;useCurrent()&lt;/code&gt; &amp;amp; &lt;code&gt;useCurrentOnUpdate()&lt;/code&gt; to set timestamp columns default value to CURRENT_TIMESTAMP.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Schema::create('table', function (Blueprint $table) {  
     ....
     $table-&amp;gt;timestamp('created_at')-&amp;gt;useCurrent();
     $table-&amp;gt;timestamp('updated_at')-&amp;gt;useCurrentOnUpdate();     
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>laravel</category>
      <category>php</category>
      <category>programming</category>
    </item>
    <item>
      <title>Laravel 9 - Rate Limiting: Global and for Guests/Users</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Sun, 19 Feb 2023 16:24:21 +0000</pubDate>
      <link>https://dev.to/sandrocagara/rate-limiting-global-and-for-guestsusers-5o0</link>
      <guid>https://dev.to/sandrocagara/rate-limiting-global-and-for-guestsusers-5o0</guid>
      <description>&lt;p&gt;You can limit some URL to be called a maximum of 60 times per minute, with &lt;code&gt;throttle:60,1&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::middleware('auth:api', 'throttle:60,1')-&amp;gt;group(function () {
    Route::get('/user', function () {
        // code here
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But also, you can do it separately for public and for logged-in users:&lt;br&gt;
&lt;strong&gt;Reminder&lt;/strong&gt;: maximum of 10 requests for guests, 60 for authenticated users&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::middleware('throttle:10|60,1')-&amp;gt;group(function () {
    // code here
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, you can have a DB field users.rate_limit and limit the amount for specific user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::middleware('auth:api', 'throttle:rate_limit,1')-&amp;gt;group(function () {
    Route::get('/user', function () {
        // code here
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>Laravel - Maintenance Mode (artisan)</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Fri, 06 Jan 2023 13:41:18 +0000</pubDate>
      <link>https://dev.to/sandrocagara/laravel-maintenance-mode-artisan-43fd</link>
      <guid>https://dev.to/sandrocagara/laravel-maintenance-mode-artisan-43fd</guid>
      <description>&lt;p&gt;If you want to enable maintenance mode on your page, execute the down Artisan command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan down
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then people would see default 503 status page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23i3kt74d5uub3vsuftx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F23i3kt74d5uub3vsuftx.png" alt="Image description" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may also provide flags, in Laravel 8:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the path the user should be redirected to&lt;/li&gt;
&lt;li&gt;the view that should be prerendered&lt;/li&gt;
&lt;li&gt;secret phrase to bypass maintenance mode&lt;/li&gt;
&lt;li&gt;retry page reload every X seconds
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan down --redirect="/" --render="errors::503" --secret="1630542a-246b-4b66-afa1-dd72a4c43515" --retry=60
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before Laravel 8:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;message that would be shown&lt;/li&gt;
&lt;li&gt;retry page reload every X seconds&lt;/li&gt;
&lt;li&gt;still allow the access to some IP address
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan down --message="Upgrading Database" --retry=60 --allow=127.0.0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you've done the maintenance work, just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>laravel</category>
      <category>programming</category>
    </item>
    <item>
      <title>Laravel 9 - Prunable trait to automatically remove models from your database</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Wed, 28 Sep 2022 14:48:52 +0000</pubDate>
      <link>https://dev.to/sandrocagara/laravel-9-prunable-trait-to-automatically-remove-models-from-your-database-206p</link>
      <guid>https://dev.to/sandrocagara/laravel-9-prunable-trait-to-automatically-remove-models-from-your-database-206p</guid>
      <description>&lt;p&gt;You can use the &lt;strong&gt;Prunable&lt;/strong&gt; trait to automatically remove models from your database. &lt;/p&gt;

&lt;p&gt;(ex.) You can permanently remove soft deleted models after a few days.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ExampleClass extends Model
{
    use SoftDeletes;
    use Prunable;

    public function prunable()
    {
        // Files matching this query will be pruned
        return static::query()-&amp;gt;where('deleted_at', '&amp;lt;=', now()-&amp;gt;subDays(14));
    }

    protected function pruning()
    {
        // Remove the file from s3 before deleting the model
        Storage::disk('s3')-&amp;gt;delete($this-&amp;gt;filename);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add PruneCommand to your schedule (app/Console/Kernel.php)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$schedule-&amp;gt;command(PruneCommand::class)-&amp;gt;daily();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Laravel 8 - Blade directive to add true/false conditions</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Wed, 31 Aug 2022 14:19:57 +0000</pubDate>
      <link>https://dev.to/sandrocagara/laravel-8-blade-directive-to-add-truefalse-conditions-344a</link>
      <guid>https://dev.to/sandrocagara/laravel-8-blade-directive-to-add-truefalse-conditions-344a</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/class"&gt;@class&lt;/a&gt;&lt;/strong&gt; Blade directive to add true/false conditions on whether some CSS class should be added.&lt;/p&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="@if ($active) underline @endif"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div @class(['underline' =&amp;gt; $active])&amp;gt;

&amp;lt;span @class([
    'p-4',
    'font-bold' =&amp;gt; $isActive,
    'text-gray-500' =&amp;gt; !$isActive,
    'bg-red' =&amp;gt; $hasError,
])&amp;gt;&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>php</category>
      <category>programming</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Laravel 9 - New scalar() method</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Mon, 22 Aug 2022 13:41:00 +0000</pubDate>
      <link>https://dev.to/sandrocagara/laravel-9-new-scalar-method-4cna</link>
      <guid>https://dev.to/sandrocagara/laravel-9-new-scalar-method-4cna</guid>
      <description>&lt;p&gt;In &lt;strong&gt;Laravel 9.8.0&lt;/strong&gt;, the &lt;em&gt;scalar()&lt;/em&gt; method was added that allows you to retrieve the first column of the first row from the query result.&lt;/p&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB::selectOne("SELECT COUNT(CASE WHEN food = 'burger' THEN 1 END) AS burgers FROM menu_items")-&amp;gt;burgers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB::scalar("SELECT COUNT(CASE WHEN food = 'burger' THEN 1 END) FROM menu_items")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>php</category>
      <category>laravel</category>
      <category>database</category>
      <category>programming</category>
    </item>
    <item>
      <title>Laravel 9 - Check Multiple Permissions at Once</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Sat, 30 Jul 2022 16:21:00 +0000</pubDate>
      <link>https://dev.to/sandrocagara/laravel-9-check-multiple-permissions-at-once-53g8</link>
      <guid>https://dev.to/sandrocagara/laravel-9-check-multiple-permissions-at-once-53g8</guid>
      <description>&lt;p&gt;In addition to &lt;strong&gt;&lt;code&gt;@can&lt;/code&gt;&lt;/strong&gt; Blade directive, did you know you can check multiple permissions at once with &lt;strong&gt;&lt;code&gt;@canany&lt;/code&gt;&lt;/strong&gt; directive?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@canany(['update', 'view', 'delete'], $post)
    // This user can update, view, or delete
@elsecanany(['create'], \App\Example::class)
    // This user can create
@endcanany
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>php</category>
      <category>webdev</category>
      <category>laravel</category>
      <category>programming</category>
    </item>
    <item>
      <title>Laravel 9 - Avoid data leakage when using orWhere on a relationship</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Sat, 16 Jul 2022 10:43:34 +0000</pubDate>
      <link>https://dev.to/sandrocagara/laravel-9-avoid-data-leakage-when-using-orwhere-on-a-relationship-1nlj</link>
      <guid>https://dev.to/sandrocagara/laravel-9-avoid-data-leakage-when-using-orwhere-on-a-relationship-1nlj</guid>
      <description>&lt;p&gt;Not Bad:&lt;br&gt;
&lt;small&gt;This returns ALL posts where votes are greater than or equal to 100 are returned.&lt;/small&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$user-&amp;gt;posts()-&amp;gt;where('active', 1)-&amp;gt;orWhere('votes', '&amp;gt;=', 100)-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good:&lt;br&gt;
&lt;small&gt;This returns Users posts where votes are greater than or equal to 100 are returned.&lt;/small&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use Illuminate\Database\Eloquent\Builder;

$users-&amp;gt;posts()-&amp;gt;where(function (Builder $query) {
     return $query-&amp;gt;where('active', 1)-&amp;gt;orWhere('votes', '&amp;gt;=', 100);
})-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>laravel</category>
      <category>php</category>
    </item>
    <item>
      <title>Angular - Use ChangeDetectionStrategy.OnPush</title>
      <dc:creator>Sandro Jhuliano Cagara</dc:creator>
      <pubDate>Sun, 26 Jun 2022 16:45:45 +0000</pubDate>
      <link>https://dev.to/sandrocagara/angular-use-changedetectionstrategyonpush-4n0g</link>
      <guid>https://dev.to/sandrocagara/angular-use-changedetectionstrategyonpush-4n0g</guid>
      <description>&lt;p&gt;Angular gives us an option to choose the &lt;code&gt;ChangeDetectionStrategy&lt;/code&gt; of a component. By default, the value is &lt;code&gt;Default&lt;/code&gt;. It's recommended to change that to &lt;code&gt;OnPush&lt;/code&gt; strategy to maximize the performance.&lt;/p&gt;

&lt;p&gt;By default, Angular run its change detection cycle on all the components whenever there occurs some changes, like a simple click event or when we receive data from ajax calls. Running change detection cycle on every such events are costly and may affect the performance.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;We can minimize these checks by setting our component's &lt;code&gt;changeDetection&lt;/code&gt; to &lt;code&gt;ChangeDetectionStrategy.OnPush&lt;/code&gt;. This will tell Angular to run change detection cycle only when:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;Input&lt;/code&gt; reference changes.&lt;/li&gt;
&lt;li&gt;Some event occurs in the component or any of the children.&lt;/li&gt;
&lt;/ol&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component({
  selector: 'app-selector',
  ...
  changeDetection: ChangeDetectionStrategy.OnPush
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Make use of &lt;code&gt;detectChanges()&lt;/code&gt; or &lt;code&gt;markForCheck()&lt;/code&gt; functions of &lt;code&gt;ChangeDetectorRef&lt;/code&gt; to explicitely run the change detection cycle if required.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Resources:&lt;/strong&gt; &lt;a href="https://netbasal.com/a-comprehensive-guide-to-angular-onpush-change-detection-strategy-5bac493074a4" rel="noopener noreferrer"&gt;A Comprehensive Guide to Angular onPush Change Detection Strategy&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Thanks to &lt;a class="mentioned-user" href="https://dev.to/fyodorio"&gt;@fyodorio&lt;/a&gt; .&lt;/p&gt;

</description>
      <category>angular</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
