<?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>Forem: AriaieBOY</title>
    <description>The latest articles on Forem by AriaieBOY (@ariaieboy).</description>
    <link>https://forem.com/ariaieboy</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%2F688500%2F91bdc365-7214-44bb-9576-1e569a3cdf50.jpg</url>
      <title>Forem: AriaieBOY</title>
      <link>https://forem.com/ariaieboy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ariaieboy"/>
    <language>en</language>
    <item>
      <title>What is a Laravel Macro, and how can you write an IDE Helper for a Macro?</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Fri, 08 Sep 2023 19:45:28 +0000</pubDate>
      <link>https://forem.com/ariaieboy/what-is-a-laravel-macro-and-how-can-you-write-an-ide-helper-for-a-macro-293g</link>
      <guid>https://forem.com/ariaieboy/what-is-a-laravel-macro-and-how-can-you-write-an-ide-helper-for-a-macro-293g</guid>
      <description>&lt;h2&gt;
  
  
  What is a Macro in Laravel?
&lt;/h2&gt;

&lt;p&gt;Macro is a simple mechanism that lets you add extra functionality to the classes that use the Macroable trait.&lt;/p&gt;

&lt;p&gt;For example, in my &lt;a href="https://github.com/ariaieboy/filament-jalali-datetime"&gt;filament-jalali-datetime&lt;/a&gt; plugin for filament, I added a &lt;code&gt;jalaliDate&lt;/code&gt; method to the filament &lt;code&gt;TextColumn&lt;/code&gt; class using the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;TextColumn&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;macro&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'jalaliDate'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;?string&lt;/span&gt; &lt;span class="nv"&gt;$format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;?string&lt;/span&gt; &lt;span class="nv"&gt;$timezone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;static&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$format&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'filament-jalali-datetime.date_format'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;formatStateUsing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Column&lt;/span&gt; &lt;span class="nv"&gt;$column&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$format&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$timezone&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;?string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="cd"&gt;/** @var TextColumn $column */&lt;/span&gt;

                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;blank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$state&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Jalalian&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;fromCarbon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Carbon&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setTimezone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$timezone&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="nv"&gt;$column&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getTimezone&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
                    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$format&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can add new functionality to any class that uses the &lt;code&gt;Illuminate\Support\Traits\Macroable&lt;/code&gt; trait.&lt;/p&gt;

&lt;p&gt;It's valuable, especially when you want to add new functionality to the core components of the framework and share it as a package.&lt;/p&gt;

&lt;h2&gt;
  
  
  The IDE-Helper
&lt;/h2&gt;

&lt;p&gt;Laravel Macros are magical, and your IDE might not detect them correctly, so to have better IDE support, you must create some IDE helpers so the IDE can see your macros.&lt;/p&gt;

&lt;p&gt;The simplest way I found is an &lt;code&gt;ide_helpers.stubs.php&lt;/code&gt; on the root that contains the signature of your macros; for example, for my &lt;code&gt;jalaliDate&lt;/code&gt; method, I created this file, and my IDE can detect this method without any problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Filament\Tables\Columns&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TextColumn&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="cd"&gt;/**
         * @source packages/filament-jalali-datetime/src/FilamentJalaliDatetimeServiceProvider.php:28
         */&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;jalaliDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;?string&lt;/span&gt; &lt;span class="nv"&gt;$format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;?string&lt;/span&gt; &lt;span class="nv"&gt;$timezone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is also a package to create automatic IDE-Helpers for macros named &lt;a href="https://github.com/KristofMorva/laravel-ide-macros"&gt;tutorigo/laravel-ide-macros&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you have any other option to create IDE-Helpers for Laravel macros, you can share it in the comments.atabases, Object Storage, and git repositories.&lt;br&gt;
I need to check the integrity of the backup files.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>idehelper</category>
      <category>tips</category>
    </item>
    <item>
      <title>How I improved my backup strategies using TrueNAS Scale</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Fri, 01 Sep 2023 15:08:08 +0000</pubDate>
      <link>https://forem.com/ariaieboy/how-i-improved-my-backup-strategies-using-truenas-scale-53de</link>
      <guid>https://forem.com/ariaieboy/how-i-improved-my-backup-strategies-using-truenas-scale-53de</guid>
      <description>&lt;p&gt;In my previous blog post &lt;a href="https://ariaieboy.ir/blog/12-how-do-i-backup-my-websites/"&gt;How do I backup my websites, and why should I improve&lt;/a&gt;, I described how I backup my websites.&lt;/p&gt;

&lt;p&gt;In that article, I mentioned some problems with my backup plans. Since then I deployed a local NAS in my home using TrueNAS and improved my backup plans.&lt;/p&gt;

&lt;h3&gt;
  
  
  Redaundent storage using Raid-1
&lt;/h3&gt;

&lt;p&gt;The first improvement is my Raid-1 configuration for backup storage.&lt;br&gt;
This means that in the event of one of my drives failing, I can restore my backed-up files from the other disk.&lt;/p&gt;

&lt;h3&gt;
  
  
  Object storage backup
&lt;/h3&gt;

&lt;p&gt;One missing part of my backup process was the object storage.&lt;br&gt;
Thanks to TrueNAS, I can easily backup my object storage files using TrueNAS Data Protection Cloud Sync Task.&lt;br&gt;
It will sync my object storage files with my Local NAS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gickup for git backup
&lt;/h3&gt;

&lt;p&gt;Another service that I run is Gickup, which backup all my remote git repositories to my local NAS.&lt;/p&gt;

&lt;h3&gt;
  
  
  One last thing: Backup health check
&lt;/h3&gt;

&lt;p&gt;Right now, I backup multiple things like my Databases, Object Storage, and git repositories.&lt;br&gt;
I need to check the integrity of the backup files.&lt;/p&gt;

</description>
      <category>backup</category>
      <category>automation</category>
      <category>truenas</category>
    </item>
    <item>
      <title>Why should you consider using AVIF on your website?</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Fri, 25 Aug 2023 16:50:59 +0000</pubDate>
      <link>https://forem.com/ariaieboy/why-should-you-consider-using-avif-on-your-website-3n3o</link>
      <guid>https://forem.com/ariaieboy/why-should-you-consider-using-avif-on-your-website-3n3o</guid>
      <description>&lt;h2&gt;
  
  
  What is AVIF?
&lt;/h2&gt;

&lt;p&gt;If you are reading tech news this day, you probably heard about the AV1 video coding format.&lt;br&gt;
AV1 will reduce file sizes without losing quality. It's the next big coding format that big tech giants start supporting in their hardware and software.&lt;br&gt;
AVIF is AV1 Image File Format. It uses AV1 to reduce image file sizes.&lt;br&gt;
AVIF and AV1 were built by the Alliance for Open Media, a non-profit industry consortium that develops open, royalty-free technology for multimedia delivery.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why should you use AVIF?
&lt;/h2&gt;

&lt;p&gt;AVIF is excellent at reducing image file sizes without losing quality. There are many comparisons, but I like &lt;a href="https://www.ctrl.blog/entry/webp-avif-comparison.html"&gt;this post&lt;/a&gt; from ctrl.blog.&lt;br&gt;
According to this post&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;AVIF outperformed both JPEG and WebP for every image in the test. AVIF's 85th percentile was the same as WebP's 15th percentile! A median saving of -50 % at the same DSSIM is a very good result!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  But why should we use AVIF now?
&lt;/h2&gt;

&lt;p&gt;If you heard about AVIF before, you probably know about its benefits compared to the WEBP. You can find great in-depth articles about the format and the technical details of how AVIF and AV1 work.&lt;/p&gt;

&lt;p&gt;But you should consider using AVIF now because, unlike WEBP, AVIF will be the next modern image format for the web.&lt;/p&gt;

&lt;p&gt;AVIF was released in 2019, and only four years later, almost every modern browser supports it &lt;a href="https://caniuse.com/avif"&gt;(resource)&lt;/a&gt;. while WEBP adoption was much slower; for example, Firefox added webp support nine years after the initial release, and Safari added support after ten years.&lt;/p&gt;

&lt;p&gt;As I mentioned above, AVIF was developed by AOM, a non-profit industry consortium that Amazon, Cisco, Google, Intel, Microsoft, Mozilla, and Netflix founded.&lt;br&gt;
And right now, it has over 43 members.&lt;/p&gt;

&lt;p&gt;All this shows that, unlike WEBP, the AVIF adoption will be much faster. And you can start adopting the AVIF format in your sites to increase performance and reduce bandwidth usage.&lt;/p&gt;

</description>
      <category>avif</category>
      <category>optimization</category>
      <category>performance</category>
    </item>
    <item>
      <title>How do I backup my websites, and why should I improve</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Fri, 18 Aug 2023 13:32:22 +0000</pubDate>
      <link>https://forem.com/ariaieboy/how-do-i-backup-my-websites-and-why-should-i-improve-2462</link>
      <guid>https://forem.com/ariaieboy/how-do-i-backup-my-websites-and-why-should-i-improve-2462</guid>
      <description>&lt;p&gt;In the old days, I didn't have any backup plans, and the only time I needed my website backed up, I was lucky that my host provider had an automatic backup system. I could restore my website using those backups, but I lost a week of data because the hosting provider would back up the host weekly.&lt;/p&gt;

&lt;p&gt;I do not use a shared host these days, and I manage my servers, so I need to back up my websites personally.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should I backup?
&lt;/h2&gt;

&lt;p&gt;Determining which data requires backup and the frequency of changes is critical.&lt;/p&gt;

&lt;p&gt;To determine the needed data, we can think that our server is gone, and we want to restore our website to its current state.&lt;/p&gt;

&lt;p&gt;In my case, I need to know the services that my website needs, for example, the web server, application, database, object storage, and cache services.&lt;/p&gt;

&lt;p&gt;Then I need to recreate these services using my website source code and run those on my new server.&lt;/p&gt;

&lt;p&gt;After running the services, I first need to restore my databases. And if required, my object storage files.&lt;/p&gt;

&lt;h2&gt;
  
  
  How am I backing up my websites
&lt;/h2&gt;

&lt;p&gt;I back up my databases to another server at least once daily. And in some cases, multiple times a day based on the application traffic.&lt;/p&gt;

&lt;p&gt;I back up my codebases on my local machine and the remote git repository hosted on GitHub or GitLab.&lt;/p&gt;

&lt;p&gt;Since I use docker for development, All my websites have a docker-compose file that can recreate all required services for the website.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is missing?
&lt;/h2&gt;

&lt;p&gt;The big missing part is the object storage part. I need to implement a way to automatically back up my files from my self-hosted object storage into another server.&lt;/p&gt;

&lt;p&gt;I must implement the 3-2-1 strategy for all my backups.&lt;/p&gt;

&lt;p&gt;I need to document the restoration process for each website.&lt;/p&gt;

&lt;p&gt;Implement a way to verify the health of the backup files; the last thing I want is a corrupted backup file. &lt;/p&gt;

</description>
      <category>backup</category>
    </item>
    <item>
      <title>Laravel Pint: Easy-to-use Code Style Fixer For Artisans</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Fri, 11 Aug 2023 20:09:00 +0000</pubDate>
      <link>https://forem.com/ariaieboy/laravel-pint-easy-to-use-code-style-fixer-for-artisans-bj</link>
      <guid>https://forem.com/ariaieboy/laravel-pint-easy-to-use-code-style-fixer-for-artisans-bj</guid>
      <description>&lt;p&gt;For Laravel developers, having a standardized code style for each project is crucial.&lt;/p&gt;

&lt;p&gt;It makes the code more readable and gives the entire project a uniform look.&lt;/p&gt;

&lt;p&gt;However, adhering to these guidelines while focusing on writing code can be challenging.&lt;/p&gt;

&lt;p&gt;Thankfully, code-style fixers like Prettier in the JS ecosystem and PHP-CS-Fixer in PHP exist to take care of this issue.&lt;/p&gt;

&lt;p&gt;But installing and configuring these tools can pose a challenge.&lt;/p&gt;

&lt;p&gt;That's where Laravel Pint comes in - it provides a pre-configured PHP-CS-Fixer for use in Laravel projects.&lt;/p&gt;

&lt;p&gt;To install it, run the command &lt;code&gt;composer requires laravel/pint --dev&lt;/code&gt; in your Laravel project.&lt;/p&gt;

&lt;p&gt;Then, to fix your Laravel project file styles, run the &lt;code&gt;./vendor/bin/pint&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Laravel Pint is highly customizable, and you can configure it to suit your needs with a JSON config file.&lt;/p&gt;

&lt;p&gt;It also uses pre-existing rules from PHP-CS-Fixer in your configuration, making it a more straightforward and uncomplicated option.&lt;/p&gt;

&lt;p&gt;The default configuration works for most Laravel projects, making Laravel Pint a must-have code-style fixer for Laravel developers.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>codestyling</category>
      <category>laravelpint</category>
    </item>
    <item>
      <title>Code-splitting and Lazy-loading Alpine Components using Async Alpine</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Sat, 22 Jul 2023 13:27:15 +0000</pubDate>
      <link>https://forem.com/ariaieboy/code-splitting-and-lazy-loading-alpine-components-using-async-alpine-5cnp</link>
      <guid>https://forem.com/ariaieboy/code-splitting-and-lazy-loading-alpine-components-using-async-alpine-5cnp</guid>
      <description>&lt;p&gt;Code-splitting and Lazy-loading Alpine Components using Async Alpine&lt;/p&gt;

&lt;p&gt;With AlpineJs, you can create components in two ways: using inline HTML markup or the &lt;code&gt;Alpine.data()&lt;/code&gt; function to define a component globally and use it throughout the entire project.&lt;/p&gt;

&lt;p&gt;Each approach has its pros and cons. For example, It is not possible to cache the inline components. And are only reusable if you use your template engine to create reusable components. The benefit of this approach is that you don't need a build step; you can add the AlpineJS to your HTML markup using CDN and start building your application.&lt;/p&gt;

&lt;p&gt;On the other hand, using &lt;code&gt;Alpine.data()&lt;/code&gt; to declare the components, you can reuse them and cache them like other static files. This option has some downsides too.&lt;br&gt;
You must set up a bundler like Vite or Webpack to bundle the codes. And if you have a big project, your bundled file size can grow over time.&lt;/p&gt;

&lt;p&gt;To fix these issues, you can use Async Alpine to split your components into individual files and load them only when needed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;You can use Async Alpine using CDN or npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/async-alpine@1.x.x/dist/async-alpine.script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;defer&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you want to use CDN, you must load Async Alpine before loading the Alpine itself.&lt;/p&gt;

&lt;p&gt;Install from npm with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;async-alpine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Import it into your bundle alongside Alpine and run AsyncAlpine.init(Alpine) and AsyncAlpine.start() before Alpine.start():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;AsyncAlpine&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;async-alpine&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Alpine&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;alpinejs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;AsyncAlpine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Alpine&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;AsyncAlpine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;Alpine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;To use Async Alpine, you must create your components in individual files using ES Module format like the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// publicly available at `/assets/path-to-component.js`&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;myComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my component has initialised!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After creating components in separate files, you can load them using one of these four options depending on your environment:&lt;br&gt;
URL Components — most straightforward implementation declaring component URLs in JS;&lt;br&gt;
Data Components — for building tools with dynamic import/code-splitting like Vite, WebPack, Rollup, and Parcel;&lt;br&gt;
Alias Loading — if your components are in a very consistent file-system structure;&lt;br&gt;
Inline Components — you need to declare components in HTML to get the asset URL, for example, using an asset CDN or for Shopify sites.&lt;/p&gt;

&lt;p&gt;After loading components, you can use them asynchronously by adding &lt;code&gt;x-ignore&lt;/code&gt; and &lt;code&gt;ax-load&lt;/code&gt; with your &lt;code&gt;x-data&lt;/code&gt; attribute like the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt;
  &lt;span class="na"&gt;x-ignore&lt;/span&gt;
  &lt;span class="na"&gt;ax-load=&lt;/span&gt;&lt;span class="s"&gt;"visible"&lt;/span&gt;
  &lt;span class="na"&gt;x-data=&lt;/span&gt;&lt;span class="s"&gt;"myComponent"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;x-text=&lt;/span&gt;&lt;span class="s"&gt;"message"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Loading Strategies
&lt;/h2&gt;

&lt;p&gt;In the code above, you can see that we used a value in the &lt;code&gt;ax-load&lt;/code&gt; attribute. You can change the loading strategy by setting these values in the &lt;code&gt;ax-load&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Eager
&lt;/h3&gt;

&lt;p&gt;It's the default behavior; if you do not provide any value, the component will load in this mode.&lt;br&gt;
In eager mode, the component will start loading immediately on page load.&lt;br&gt;
It will still load asynchronously in the background but with the highest priority possible.&lt;/p&gt;

&lt;p&gt;This mode is useful when you want a component to be interactive as soon as possible.&lt;/p&gt;
&lt;h3&gt;
  
  
  Idle
&lt;/h3&gt;

&lt;p&gt;It uses requestIdleCallback, where it's supported to load when the main thread is less busy.&lt;br&gt;
Components not critical to the initial load are bests for this scenario.&lt;/p&gt;
&lt;h3&gt;
  
  
  Visible
&lt;/h3&gt;

&lt;p&gt;It uses IntersectionObserver only to load when the component is in view, similar to lazy-loading images.&lt;/p&gt;
&lt;h3&gt;
  
  
  Media
&lt;/h3&gt;

&lt;p&gt;The component will be loaded when the provided media query is true.&lt;/p&gt;
&lt;h3&gt;
  
  
  Event
&lt;/h3&gt;

&lt;p&gt;The component will be loaded once it receives the async-alpine:load event on the window. Provide the id of the component in detail.id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- on a button click using Alpine's $dispatch --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;x-data&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"$dispatch('async-alpine:load', { id: 'my-component-1' })"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Load component&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt;
  &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my-component-1"&lt;/span&gt;
  &lt;span class="na"&gt;x-ignore&lt;/span&gt;
  &lt;span class="na"&gt;ax-load=&lt;/span&gt;&lt;span class="s"&gt;"event"&lt;/span&gt;
  &lt;span class="na"&gt;x-data=&lt;/span&gt;&lt;span class="s"&gt;"componentName"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- load our component after `another-library-init` has loaded --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;another-library-init&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dispatchEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;CustomEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;async-alpine:load&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-component-2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}))&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt;
  &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my-component-2"&lt;/span&gt;
  &lt;span class="na"&gt;x-ignore&lt;/span&gt;
  &lt;span class="na"&gt;ax-load=&lt;/span&gt;&lt;span class="s"&gt;"media (prefers-reduced-motion: no-preference)"&lt;/span&gt;
  &lt;span class="na"&gt;x-data=&lt;/span&gt;&lt;span class="s"&gt;"componentName"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more information and more detailed examples, you can check out the official document of Async Alpine &lt;a href="https://async-alpine.dev/docs/"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>alpinejs</category>
      <category>async</category>
      <category>lazyload</category>
      <category>performance</category>
    </item>
    <item>
      <title>Free Performance + Extra features for Laravel using Octane and Swoole</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Sat, 22 Jul 2023 13:26:02 +0000</pubDate>
      <link>https://forem.com/ariaieboy/free-performance-extra-features-for-laravel-using-octane-and-swoole-1n8g</link>
      <guid>https://forem.com/ariaieboy/free-performance-extra-features-for-laravel-using-octane-and-swoole-1n8g</guid>
      <description>&lt;h2&gt;
  
  
  How Laravel Octane Boosts Performance?
&lt;/h2&gt;

&lt;p&gt;As you know, in traditional Laravel applications, the PHP process will run the application from the ground up with each request, and the PHP process can only handle one request at a time.&lt;/p&gt;

&lt;p&gt;But in Laravel Octane, the application will bootstrap once at the first request to the ram. After that, every request that hits the server will serve using the bootstrapped application in the ram instead of running the application from the ground up.&lt;/p&gt;

&lt;p&gt;Another feature is that Laravel Octane can run multiple workers at once, so instead of handling one request at a time, it can take multiple requests at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  How much faster is Octane?
&lt;/h2&gt;

&lt;p&gt;A quick search in the internet you can find lots of benchmarks on the internet, but for a quick comparison, I  tested my website using both Laravel Octane (swoole) and nginx + PHP-fpm with default settings and did a benchmark using this command:&lt;br&gt;
&lt;code&gt;ab -t 10 -c http://localhost&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And here is the result:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nginx&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.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%2Fmzhpb1t0nbzv1zi2ocvd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fmzhpb1t0nbzv1zi2ocvd.png" alt="nginx"&gt;&lt;/a&gt;&lt;br&gt;
&lt;code&gt;octane&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.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%2Ffov9p27cbnjyabcbscsd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Ffov9p27cbnjyabcbscsd.png" alt="octane"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the results above, it's about 25% faster than nginx-fpm.&lt;/p&gt;

&lt;p&gt;Based on the configurations, it can perform much faster with fewer resources, but 25-30% boosts are a lot.&lt;/p&gt;

&lt;p&gt;Boosting Performance is one of many things that Laravel Octane can do.&lt;/p&gt;

&lt;p&gt;Laravel Octane under the hood uses some drivers to run the workers and bootstrap the application to the ram, including swoole, openswoole, and Roadrunner.&lt;/p&gt;

&lt;p&gt;If you use swoole as the driver, you can access some cool extra features that can be useful depending on your application.&lt;/p&gt;
&lt;h3&gt;
  
  
  Concurrent Tasks
&lt;/h3&gt;

&lt;p&gt;You can run operations concurrently using swoole task workers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$servers&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Octane&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;concurrently&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
 &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
 &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Server&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the functions above will run in parallel using swoole task workers. Isn't that awesome?&lt;/p&gt;

&lt;h3&gt;
  
  
  The Octane Cache
&lt;/h3&gt;

&lt;p&gt;Octane using Swoole Table provides a cache driver that can handle up to 2 million reads and write operations per second.&lt;/p&gt;

&lt;p&gt;You can also interact directly with Swoole Table using these codes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Octane&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'example'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'uuid'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
 &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Nuno Maduro'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="s1"&gt;'votes'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Octane&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'example'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'uuid'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Ticks &amp;amp; Intervals
&lt;/h2&gt;

&lt;p&gt;Using Octane with Swoole allows you to execute callables every specified second.&lt;/p&gt;

&lt;p&gt;For example, the code below will run each 20 seconds after the application startup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Octane&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;tick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'simple-ticker'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;ray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Ticking...'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
 &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How can you use Laravel Octane?
&lt;/h2&gt;

&lt;p&gt;There is a good installation tutorial in the Laravel doc itself &lt;a href="https://laravel.com/docs/10.x/octane#installation" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You need to install the drivers on your server first. For example, for installing swoole, you can use pecl:&lt;br&gt;
&lt;code&gt;pecl install swoole&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After that, you need to install the laravel Octane itself using the code below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require laravel/octane&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then you need to run this command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan octane:install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And at the end, for serving your application, you can use this artisan command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan octane:start&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  But can I use Octane on all Laravel applications?
&lt;/h2&gt;

&lt;p&gt;The quick answer is Yes and also No!&lt;/p&gt;

&lt;p&gt;You can use Octane on all Laravel applications, but since it handles requests differently, you must check that your application is compatible with Octane.&lt;/p&gt;

&lt;p&gt;For example, your application's service providers &lt;code&gt;register&lt;/code&gt; and &lt;code&gt;boot&lt;/code&gt; methods will only be executed once when the request worker initially boots.&lt;/p&gt;

&lt;p&gt;Because of that, You should double-check the injections in your &lt;code&gt;boot&lt;/code&gt; and &lt;code&gt;register&lt;/code&gt; methods.&lt;/p&gt;

&lt;p&gt;You can read about the &lt;a href="https://laravel.com/docs/10.x/octane#dependency-injection-and-octane" rel="noopener noreferrer"&gt;Dependency Injection &amp;amp; Octane&lt;/a&gt; in the Laravel Doc.&lt;/p&gt;

&lt;p&gt;If you use Larastan, there is a rule that you can use to check Octane Compatibility. You can enable this rule by setting this parameter in your &lt;code&gt;phpstan.neon&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parameters:
    checkOctaneCompatibility: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But don't be afraid of compatibility problems and memory leaks. After using Octane for almost two years, I only encounter one memory leak in &lt;code&gt;barryvdh/laravel-debugbar&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since You only use the debug bar in the development environment, it might not be a big deal. Still, I replaced it with &lt;code&gt;itsgoingd/clockwork&lt;/code&gt;, and I can tell you it's as good as the laravel debug bar, and it supports Octane without any memory leak or compatibility problem.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>octane</category>
      <category>swoole</category>
      <category>performance</category>
    </item>
    <item>
      <title>ZSH Plugin for Laravel Sail</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Sat, 22 Jul 2023 13:23:21 +0000</pubDate>
      <link>https://forem.com/ariaieboy/zsh-plugin-for-laravel-sail-4cep</link>
      <guid>https://forem.com/ariaieboy/zsh-plugin-for-laravel-sail-4cep</guid>
      <description>&lt;h2&gt;
  
  
  What is Laravel Sail
&lt;/h2&gt;

&lt;p&gt;Laravel Sail is a development environment that uses docker under the hood.&lt;br&gt;
By using Laravel Sail, you can use the power of docker without knowing much about it.&lt;br&gt;
It has pre-defined services for your applications, including a web server, database, Redis, etc.&lt;/p&gt;

&lt;p&gt;Sail also provides a CLI tool that helps you to manage the services and run commands like artisan, composer, npm, etc.&lt;br&gt;
For example, you can start the service containers using &lt;code&gt;./vendor/bin/sail up&lt;/code&gt; or run artisan commands using &lt;code&gt;./vendor/bin/sail artisan&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Laravel Sail ZSH Plugin features
&lt;/h2&gt;

&lt;p&gt;As you can see from the examples above, you need to use the sail binary file path to run these commands.&lt;/p&gt;

&lt;p&gt;I've created a plugin for ZSH with lots of aliases, so you can use Laravel Sail with shorter commands.&lt;/p&gt;

&lt;p&gt;For example, you can start the service containers using the &lt;code&gt;sup&lt;/code&gt; alias or run composer commands using the &lt;code&gt;sc&lt;/code&gt; alias instead of &lt;code&gt;./vendor/bin/sail composer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Aside from simple aliases, the plugin also lets you use these aliases in any project sub-directories without you needing to provide the path to sail binary.&lt;/p&gt;

&lt;p&gt;It also provides some basic autocompletion for the commands.&lt;/p&gt;

&lt;p&gt;Another feature that makes this plugin much more helpful than a simple set of aliases is that you can install composer and npm dependencies using &lt;code&gt;s cinit&lt;/code&gt; and &lt;code&gt;ninit&lt;/code&gt; commands.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to install this plugin
&lt;/h2&gt;

&lt;p&gt;Run this command in your terminal and clone the source code to your ohmyzsh plugin directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; git clone &lt;span class="nt"&gt;--depth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 https://github.com/ariaieboy/laravel-sail &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;ZSH_CUSTOM&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="p"&gt;~/.oh-my-zsh/custom&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/plugins/laravel-sail
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then open the &lt;code&gt;~/.zshrc&lt;/code&gt; file in the editor of your choice and add &lt;code&gt;laravel-sail&lt;/code&gt; to your ohmyzsh plugins list.&lt;/p&gt;

&lt;p&gt;You can see the list of all aliases in the link below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ariaieboy/laravel-sail/blob/main/README.md"&gt;Laravel Sail ZSH Plugin&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>laravel</category>
      <category>sail</category>
      <category>zsh</category>
    </item>
    <item>
      <title>Nala: Modern Front-End for the APT Package Manager</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Sat, 22 Jul 2023 13:21:38 +0000</pubDate>
      <link>https://forem.com/ariaieboy/nala-modern-front-end-for-the-apt-package-manager-300g</link>
      <guid>https://forem.com/ariaieboy/nala-modern-front-end-for-the-apt-package-manager-300g</guid>
      <description>&lt;p&gt;As someone that uses Laravel and PestPHP, I am used to the beautiful CLI outputs. Nala is like a skin for apt with human-friendly outputs.&lt;br&gt;
For example, look at the picture below which one do you prefer?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Ff8necenu0wpx4znqsmkl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Ff8necenu0wpx4znqsmkl.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Besides the beautiful CLI outputs, Nala adds some nice to have features to the table.&lt;/p&gt;

&lt;p&gt;The parallel download mode helps you to download lots of small and large packages faster than the default APT.&lt;/p&gt;

&lt;p&gt;Another feature is &lt;code&gt;nala fetch&lt;/code&gt; that test the latency of the available mirrors and then saves the 3 fastest mirrors and saves it in a file.&lt;/p&gt;

&lt;p&gt;Another feature that I found out about Nala while I was writing this article is &lt;code&gt;nala history&lt;/code&gt; it's like git but for the packages. It's save all installed removed or upgraded packages in var/lib/nala/history.json with a unique ID.&lt;br&gt;
You can undo or redo changes using these IDs.&lt;br&gt;
Nala is free and open-source and is written using Python.&lt;br&gt;
If you use the latest version of Debian or Ubuntu you can install it as simply as an apt install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;Nala
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or you can check their wiki about other installation options:&lt;br&gt;
&lt;a href="https://gitlab.com/volian/nala/-/wikis/Installation" rel="noopener noreferrer"&gt;Installation Page&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>packagemanager</category>
      <category>apt</category>
      <category>nala</category>
    </item>
    <item>
      <title>Translate Your Laravel Application to 78 Languages</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Sat, 22 Jul 2023 13:18:02 +0000</pubDate>
      <link>https://forem.com/ariaieboy/translate-your-laravel-application-to-78-languages-3jl5</link>
      <guid>https://forem.com/ariaieboy/translate-your-laravel-application-to-78-languages-3jl5</guid>
      <description>&lt;p&gt;Laravel has localization tools that help you translate your applications into any language you want.&lt;br&gt;
But by default, all the Laravel Lang files include the English language. And if your application needs other languages you must create and manage lang files for each language by yourself.&lt;/p&gt;

&lt;p&gt;Right now that I am writing this article we have more than 1400 keys for each language in the Laravel-Lang package that includes Laravel and its first-party packages.&lt;/p&gt;

&lt;p&gt;You can translate Laravel and its packages like Jetstream, Fortify, Cashier, etc into 78 Languages.&lt;/p&gt;

&lt;p&gt;All you need to do is to install Laravel-lang/common packages using the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require laravel-lang/common &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that you can add any languages you want using the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan lang:add en de ro zh_CN lv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Laravel often introduces new localization keys to the lang files and the community might update the translations in the future you can update the added languages using the command below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan lang:update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can translate missing keys or improve the translations and create a PR on the &lt;a href="https://github.com/Laravel-Lang/lang"&gt;Laravel-Lang/lang&lt;/a&gt;  and help improve this package.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>language</category>
    </item>
    <item>
      <title>CapRover - Easy and Free Self-Hosted PaaS!</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Sat, 22 Jul 2023 13:14:33 +0000</pubDate>
      <link>https://forem.com/ariaieboy/caprover-easy-and-free-self-hosted-paas-2f51</link>
      <guid>https://forem.com/ariaieboy/caprover-easy-and-free-self-hosted-paas-2f51</guid>
      <description>&lt;h2&gt;
  
  
  What Is Caprover ?
&lt;/h2&gt;

&lt;p&gt;If you managed a server on your own you know that configuring everything correctly is a very hard job to do.&lt;br&gt;
Handling Nginx configuration, issuing SSL Certifications securing the services, etc.&lt;br&gt;
Now imagine if you want to run more than a service on a server or you want to load balance your incoming requests between multiple servers and spin up more than one instance of a service on your servers. That's a hard job, right?&lt;br&gt;
Not with Caprover, You can manage multiple services like your NodeJS, Python, PHP, ASP.NET, and Ruby Apps or your Databases like MySQL, MongoDB, Postgres, etc. on a single server or a cluster of servers.&lt;br&gt;
It will load balance your app using a customizable Nginx proxy server and it can create free SSL certifications using Let's Encrypt.&lt;br&gt;
CapRover Has a nice WEB GUI that helps you manage your services. you can also manage your services using the CLI of the CapRover.&lt;br&gt;
Another awesome feature of CapRover is the rollback feature if you shipped a bad version on production you can easily roll back to any version of your APP with a single click.&lt;/p&gt;

&lt;h2&gt;
  
  
  But How It Is Working?
&lt;/h2&gt;

&lt;p&gt;Under the hood, CapRover uses Docker to containerize your applications. An Nginx Reverse Proxy will manage your load balancing, the Reverse Proxy will also route the incoming requests to the specified services in your server(s).&lt;br&gt;
And for clustering, Caprover uses Docker Swarm.&lt;br&gt;
In the picture below you can see how CapRover works:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p3Ghem4k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t909evr0v0uaj0tvk1bz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p3Ghem4k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t909evr0v0uaj0tvk1bz.png" alt="Caprover" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Is It Safe?
&lt;/h2&gt;

&lt;p&gt;Caprover is an open-source project and you can check both the backend and frontend codes of it in their GitHub organization.&lt;br&gt;
Since CapRover only uses docker in the background you can remove CapRover from your server any time you wanted to and your apps will continue working without any problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  But I Didn't Work With Docker Before
&lt;/h2&gt;

&lt;p&gt;CapRover has lots of one-click apps which means you can deploy lots of popular projects with a single click.&lt;br&gt;
For example, you can deploy MySql, PostgreSQL, MariaDB, Redis, WordPress, Minio, etc.&lt;br&gt;
You can find the full list of the apps &lt;a href="https://github.com/caprover/one-click-apps/tree/master/public/v4/apps"&gt;here&lt;/a&gt;.&lt;br&gt;
Besides one-click apps, there are some sample apps that you can use to practice or even deploy your application using &lt;a href="https://caprover.com/docs/sample-apps.html"&gt;these samples&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Last Word
&lt;/h3&gt;

&lt;p&gt;CapRover might not be a good option for big teams and companies but it's a really good option for individuals or small to medium teams that want to reduce their costs and enjoy the power of Docker and Nginx without having to learn them or deal with their settings scripts to make things work!! &lt;/p&gt;

</description>
      <category>caprover</category>
      <category>paas</category>
      <category>selfhost</category>
    </item>
    <item>
      <title>Test Your Codebase Without Testing It Using Larastan</title>
      <dc:creator>AriaieBOY</dc:creator>
      <pubDate>Sat, 22 Jul 2023 13:10:10 +0000</pubDate>
      <link>https://forem.com/ariaieboy/test-your-codebase-without-testing-it-using-larastan-ncn</link>
      <guid>https://forem.com/ariaieboy/test-your-codebase-without-testing-it-using-larastan-ncn</guid>
      <description>&lt;p&gt;&lt;strong&gt;Larastan&lt;/strong&gt; is a wrapper around PHPStan for Laravel, and it let you test your source codes without writing any tests.&lt;/p&gt;

&lt;p&gt;PHPStan is a static analyzer for PHP and it's working with legacy and modern codes.&lt;/p&gt;

&lt;p&gt;Since lots of Laravel works magically PHPStan needs some justification to understand the magic behind Laravel it's when Larastan comes into place.&lt;/p&gt;

&lt;p&gt;So if you have any PHP code base you can PHPStan and if you use Laravel you must go with Larastan. from here on I am gonna reference these tools as static analyzers.&lt;/p&gt;

&lt;h2&gt;
  
  
  But how it's working
&lt;/h2&gt;

&lt;p&gt;Static Analyzers scan your code base before you even run your code in development or in CI to prevent any obvious &amp;amp; tricky bugs to reach your production.&lt;/p&gt;

&lt;p&gt;PHPStan has 9 levels of rule sets that you can use on your code base. for example, level 0 only checks for:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;basic checks, unknown classes, unknown functions, unknown methods called on $this, wrong number of arguments passed to those methods and functions, always undefined variables.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's good practice to start using these tools with low levels and fix bugs and errors after you fixed all errors on that level you can bump your level up and try to make your code base more strict and bug-free.&lt;/p&gt;

&lt;p&gt;For sure Static Analyzers are not going to test all possible outcomes of your code, but they can detect lots of annoying bugs and dead codes etc. and make your code base much cleaner and bug-free.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>livewire</category>
      <category>filamentphp</category>
    </item>
  </channel>
</rss>
