<?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: Akshit Arora</title>
    <description>The latest articles on Forem by Akshit Arora (@akshitarora).</description>
    <link>https://forem.com/akshitarora</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%2F818256%2F208452ca-5634-4e70-8c2a-03f012a8ca6d.jpeg</url>
      <title>Forem: Akshit Arora</title>
      <link>https://forem.com/akshitarora</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/akshitarora"/>
    <language>en</language>
    <item>
      <title>Top 5 things a Framework is NOT responsible for!</title>
      <dc:creator>Akshit Arora</dc:creator>
      <pubDate>Wed, 02 Aug 2023 12:49:22 +0000</pubDate>
      <link>https://forem.com/akshitarora/top-5-things-a-framework-is-not-responsible-for-1in4</link>
      <guid>https://forem.com/akshitarora/top-5-things-a-framework-is-not-responsible-for-1in4</guid>
      <description>&lt;p&gt;We often complain that an XYZ framework is slow, made my application crappy, or even claim that the Framework won't be able to handle the high traffic! So, is a framework guilty for the allegations we put on it?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/Ko8G3ryOt7A1LdEv6l/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/Ko8G3ryOt7A1LdEv6l/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We always use Programming Frameworks to make development an easy job. But we must understand that frameworks are here to make our job easy, that's it. So, let us understand what framework is &lt;strong&gt;NOT&lt;/strong&gt; responsible for.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Security
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/11fot0YzpQMA0g/giphy-downsized-large.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/11fot0YzpQMA0g/giphy-downsized-large.gif" width="271" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, Frameworks do provide security at various points like making your files inaccessible directly and sanitising inputs. But, ultimately it's our responsibility to make sure everything remains secure. Making folder permissions to 777 or Disabling security features of Framework just because &lt;u&gt;&lt;em&gt;iT's aNnOyInG!&lt;/em&gt;&lt;/u&gt;  🙄 will lead your application to destruction no matter what cutting-edge framework you use! 🤷‍♂️&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Application Speed
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/bMdZu3fG2ZEBO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/bMdZu3fG2ZEBO/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Application speed depends on the System on which the application is loaded, the traffic on the system and how optimised your code/database is to handle the traffic/host. Even the benchmark tests give you a response speed in milliseconds. If your application is taking 2 minutes to load the page, it's you! Not the framework.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Optimisation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/19dm2McJ6qsxCNgZwT/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/19dm2McJ6qsxCNgZwT/giphy.gif" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's a Kaplan's law:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Give a boy a hammer and everything he meets has to be pounded&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Frameworks provide you with a lot of tools. That doesn't mean that you have to use them all to get your things done! If the new shiny feature you are using is taking a lot of resources, just skip it. Not every feature is worth using. It depends on your problem statement. True optimisation lies only in using the right method at the right moment.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Extensibility
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/26BkNRBRwdXfGsAlW/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/26BkNRBRwdXfGsAlW/giphy.gif" width="500" height="609"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Writing extensible apps are totally in the hands of the developer. Frameworks always provide extensibility out of the box. That is why we can build our code on them. But we have to make sure that whatever we are building, must be extensible. &lt;strong&gt;Pro-Tip:&lt;/strong&gt; To excel in creating extensible applications, get your basics of OOPs cleared and practice SOLID principles.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Errors and exceptions
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3oz8xYzLEsMEOWwYzS/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3oz8xYzLEsMEOWwYzS/giphy.gif" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Frameworks can provide you with great debugging and testing tools. But, It is we, the developers who have to make sure that our code has no errors and all the possible exceptions are properly managed.&lt;/p&gt;

&lt;p&gt;So, if you're ditching a framework because of any of the above-mentioned issues, think again...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/777Aby0ZetYE8/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/777Aby0ZetYE8/giphy.gif" width="500" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Laravel: How To disable Login for deactivated user?</title>
      <dc:creator>Akshit Arora</dc:creator>
      <pubDate>Sun, 12 Mar 2023 15:49:37 +0000</pubDate>
      <link>https://forem.com/akshitarora/laravel-how-to-disable-login-for-deactivated-user-3jg4</link>
      <guid>https://forem.com/akshitarora/laravel-how-to-disable-login-for-deactivated-user-3jg4</guid>
      <description>&lt;p&gt;There are cases where you just need to "Deactivate" (Not delete) the user. The use case may also be to block access temporarily for someone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Initial steps
&lt;/h3&gt;

&lt;p&gt;Add a column in the user table where you can manage the user activation status. Keeping the column name &lt;code&gt;is_active&lt;/code&gt; as of now.&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 make:migration add_is_active_to_users_table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the column in migration file's &lt;code&gt;up()&lt;/code&gt; and &lt;code&gt;down()&lt;/code&gt; functions as required.&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="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;up&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Schema&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;'users'&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;Blueprint&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'is_active'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&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="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;down&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Schema&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;'users'&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;Blueprint&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;dropColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'is_active'&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;Run the migration&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 migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Authenticating user
&lt;/h3&gt;

&lt;p&gt;To check if the user is active along with their credentials, Check out the Laravel &lt;a href="https://laravel.com/docs/10.x/authentication#authenticating-users" rel="noopener noreferrer"&gt;documentation to manually authenticate the users&lt;/a&gt; and simply add the required column's information in the &lt;code&gt;$credentials&lt;/code&gt; variable in the &lt;code&gt;authenticate()&lt;/code&gt; function of &lt;code&gt;LoginController.php&lt;/code&gt;&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="nv"&gt;$credentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="s1"&gt;'password'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="nv"&gt;$credentials&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'is_active'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! You're done! The user will not be able to login into the application if their &lt;code&gt;is_active&lt;/code&gt; value is &lt;code&gt;false&lt;/code&gt;/&lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  But, What about the Middleware way?
&lt;/h3&gt;

&lt;p&gt;When I was implementing this functionality, I found several blogs online which suggest creating the Middleware and checking your user there (Like &lt;a href="https://dev.to/techtoolindia/how-to-disable-users-from-login-in-laravel-bm9"&gt;this&lt;/a&gt; and &lt;a href="https://blog.quickadminpanel.com/3-ways-to-delete-user-in-laravel-block-hide-or-hard-delete/" rel="noopener noreferrer"&gt;this&lt;/a&gt;). But I found a flaw in this approach.&lt;/p&gt;

&lt;p&gt;The flow goes like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The deactivated user tries to log in&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The user gets authenticated successfully,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The request goes to the Middleware.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Middleware checks if the user is deactivated&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Middleware finds the user as deactivated, it logs out the user&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this flow, the &lt;code&gt;Illuminate\Auth\Events\Authenticated&lt;/code&gt; event will still get triggered as the deactivated/blocked user tries to log in. This should not be the case. The event that should be triggered is &lt;code&gt;Illuminate\Auth\Events\Failed&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The catch:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you follow the Laravel way, it will simply show the user a generic message same as when the credentials don't match as per our records. But in the middleware example, you can inform the user that you've been blocked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, should we follow the middleware approach if we want to notify the user that you're blocked?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I would still not recommend it as this flow is not as per how the Authentication works. We have to use the &lt;code&gt;attemptWhen&lt;/code&gt; functionality for additional conditions and setting up custom flash messages if required. Please check Laravel's documentation &lt;a href="https://laravel.com/docs/10.x/authentication#specifying-additional-conditions" rel="noopener noreferrer"&gt;here&lt;/a&gt; for more details. This functionality with examples may be covered later in another blog.&lt;/p&gt;

</description>
      <category>career</category>
      <category>productivity</category>
      <category>learning</category>
    </item>
    <item>
      <title>How to log your heavy database queries in your Laravel project?</title>
      <dc:creator>Akshit Arora</dc:creator>
      <pubDate>Sun, 18 Sep 2022 17:23:50 +0000</pubDate>
      <link>https://forem.com/akshitarora/how-to-log-your-heavy-database-queries-in-your-laravel-project-4ndn</link>
      <guid>https://forem.com/akshitarora/how-to-log-your-heavy-database-queries-in-your-laravel-project-4ndn</guid>
      <description>&lt;p&gt;I work in data intensive Laravel based applications. So, the biggest problem occurs as your application grows is that your application getting slowed down. Or, sometimes, the client keeps on saying that application is running slow, but it is just one query that only client is running (and God knows why and from where!).&lt;/p&gt;

&lt;p&gt;This is a common scenario when your application starts to age, the database keeps getting heavy, and somewhere, that new guy added a database query which was not optimized at all!&lt;/p&gt;

&lt;p&gt;Then we need to start the debugging process and check what went wrong! Just to overcome such a problem, (and taking this as an excuse to start my open source contribution journey), I built a Laravel package to help me track down such heavy queries. I named it as &lt;strong&gt;&lt;a href="https://github.com/akshit-arora/dblog"&gt;DBLog&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Just another Database Logger?
&lt;/h2&gt;

&lt;p&gt;Well... Not actually. I found some great logging tools already available for Laravel. One of my favorite was &lt;a href="https://github.com/overtrue/laravel-query-logger"&gt;Laravel Query Logger&lt;/a&gt;. But, I needed some more feature from that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why DBLog?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Track the slow queries.&lt;/strong&gt;: Track slow queries in the log files. (Common feature, I know)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Track queries on triggers&lt;/strong&gt;: &lt;em&gt;Inspired from Laravel Query Logger&lt;/em&gt;. Only log the queries based on the triggers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Get the page from which the query ran!&lt;/strong&gt;: Again, inspired from Laravel Query Logger, I must know the page which is running slow, not just the slow query.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Duration Bifurcated Logs&lt;/strong&gt;: &lt;em&gt;That's a unique feature I wanted&lt;/em&gt;. Just logging the slow queries was not enough, sometimes, we need to know the queries which were really slooooow. So, just set up the time brackets and it will log the query based on the time taken. Now, I have the logs of the queries which needs immediate attention and then going down the duration list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Datewise Logs&lt;/strong&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Client&lt;/strong&gt;: Hey! I ran this page last week, can you please check that page why was it slow? It's running good today though!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A very common dialog we hear! That feature, just because of that. I don't have to search a single 10 MB log file which contains queries from the past 6 months. I just need to find that date logs and check out the issues. :)&lt;/p&gt;

&lt;p&gt;So, I just started my journey to the open source contribution, (finally!!) I really hope that I can be at the service for the community. Please check the package on this &lt;a href="https://github.com/akshit-arora/dblog"&gt;Github Link&lt;/a&gt; and try it once. I appreciate your reviews, feedback and criticism on it. :)&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>database</category>
      <category>opensource</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
