<?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: Jitesh Dhamaniya</title>
    <description>The latest articles on DEV Community by Jitesh Dhamaniya (@jiteshdhamaniya).</description>
    <link>https://dev.to/jiteshdhamaniya</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%2F447958%2F84e4ff47-0d45-4646-b8d7-3ed7c1d8f525.jpeg</url>
      <title>DEV Community: Jitesh Dhamaniya</title>
      <link>https://dev.to/jiteshdhamaniya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jiteshdhamaniya"/>
    <language>en</language>
    <item>
      <title>Jobs not picking up new .env values</title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Thu, 02 Sep 2021 09:35:16 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/jobs-not-picking-up-new-env-values-1a33</link>
      <guid>https://dev.to/jiteshdhamaniya/jobs-not-picking-up-new-env-values-1a33</guid>
      <description>&lt;p&gt;if you change env, make sure to restart your supervisor or queue worker so jobs can use new .env values too. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Use @entangle to get Pikaday date value on button click in Laravel Livewire. </title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Thu, 03 Jun 2021 14:49:51 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/use-entangle-to-get-pikaday-date-value-on-button-click-in-laravel-livewire-2c8p</link>
      <guid>https://dev.to/jiteshdhamaniya/use-entangle-to-get-pikaday-date-value-on-button-click-in-laravel-livewire-2c8p</guid>
      <description>&lt;p&gt;Recently i wanted to get Pikaday value to livewire component property on seperate action, rather than onSelect event of Pikaday. But i could not find a solution online and had to do it myself hence writing to help somebody looking for something in future. &lt;/p&gt;

&lt;p&gt;And this is the code i used in a blade component e.g &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="o"&gt;@&lt;/span&gt;&lt;span class="nf"&gt;props&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;wire&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;ignore&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;
        &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"border"&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"{
       // entangle local variable to component property.
        variable: @entangle(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="s2"&gt;).defer 
        }"&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"input"&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"
        new Pikaday({
            field: &lt;/span&gt;&lt;span class="nv"&gt;$refs&lt;/span&gt;&lt;span class="s2"&gt;.input,
            format:'M/D/YYYY',
            toString(date, format) {
                // you should do formatting based on the passed format,
                // but we will just return 'D/M/YYYY' for simplicity
                const day = date.getDate();
                const month = date.getMonth() + 1;
                const year = date.getFullYear();
                return `${year}-${month}-${day}`;
            },
            onSelect: function() {
                // assign selected value to variable 
                variable = this.toString();
            }
        })"&lt;/span&gt;
        &lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;
        &lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;$attributes&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is how you going to call this component.&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-date-picker                    
                    id="startDate" // this does the thing
                    autocomplete="off"
                    placeholder="Date"
                /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the benefit of this approch is that, this does not fire any livewire event on select, so no trip to server untill i fire using another button like this.&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-button wire:click="$refresh" secondary class="text-xs"&amp;gt; Search &amp;lt;/x-buttons.link&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Parse Cookies in Next.js</title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Thu, 03 Jun 2021 14:46:29 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/parse-cookies-in-next-js-1pkb</link>
      <guid>https://dev.to/jiteshdhamaniya/parse-cookies-in-next-js-1pkb</guid>
      <description>&lt;p&gt;One thing i love and hate at the same time about node eco-system is, that there is always a package for everything and you have to use npm package/module for everything. Apparently that was also behind the success of nodejs and Ryan hated it and he said it repeatedly. Personally i don't like to use package until it is very essential. &lt;/p&gt;

&lt;p&gt;Anyways so recently i was implementing session in nextjs app and i had to parse cookies to get the token which i did set from my login api Route. I used &lt;code&gt;querystring&lt;/code&gt; module from nodejs default modules to parse it. Node has some very useful modules and they come along with node, so you always have them with you, whether you use them or not. &lt;/p&gt;

&lt;p&gt;Anyways long story short, this is what i used to parse query string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import qs from 'querystring';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cookies = qs.decode(ctx.req.headers.cookie, "; ")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ctx.req.headers.cookie&lt;/code&gt; would have something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;token: 'token_cookie_value; Proxy_session=e05hujj6o8k6j9r'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so anything, in this form can be parsed with this code and it would look like this after parsing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  token: 'token_cookie_value',
  Proxy_session: 'e05hujj6o8k6j9r'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So thats it. Simple and to the point. You can read more about querystring.parse here &lt;br&gt;
&lt;a href="https://nodejs.org/api/querystring.html#querystring_querystring_parse_str_sep_eq_options"&gt;https://nodejs.org/api/querystring.html#querystring_querystring_parse_str_sep_eq_options&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take care till next time. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Queues not running in laravel </title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Fri, 14 May 2021 06:21:07 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/queues-not-running-localhost-5bln</link>
      <guid>https://dev.to/jiteshdhamaniya/queues-not-running-localhost-5bln</guid>
      <description>&lt;p&gt;Hi, Recently when i tried to run queues on localhost, i encountered very strange problem. the command for running a queue in laravel &lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan queue:listen&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;stopped working for me. i tried &lt;code&gt;QUEUE_CONNECTION=SYNC&lt;/code&gt; which worked but any other connection would not. &lt;/p&gt;

&lt;p&gt;Later i realised it was because apparently my application was in maintenance mode or i had run &lt;code&gt;php artisan down&lt;/code&gt; command and never did this up. So even my application was running, it was according to kernel was in down or maintenance mode. once i ran command &lt;code&gt;php artisan up&lt;/code&gt;, it started working again. &lt;/p&gt;

&lt;p&gt;just wanted to write this down here, if anybody else encounter same problem. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;upon investigation i realised down command creates a file  &lt;code&gt;storage/framework/down&lt;/code&gt; which apparently tell application its in maintenance mode. &lt;code&gt;php artisan up&lt;/code&gt; simply delete this file, which let the whole application know its up. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Documentation says &lt;code&gt;--force&lt;/code&gt; flag should make it work in maintenance mode but it does not seems to work for me.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Get Nested Property from a Object in JS </title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Sat, 24 Apr 2021 11:41:34 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/get-nested-property-from-a-object-in-js-1g44</link>
      <guid>https://dev.to/jiteshdhamaniya/get-nested-property-from-a-object-in-js-1g44</guid>
      <description>&lt;p&gt;Recently Stumbled upon this nice snippet for accessing Nested property using String.&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="cm"&gt;/**
 * get property of object
 * @param obj object
 * @param path e.g user.name
 */&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;defaultValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;-&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;defaultValue&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;and this how you use it&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="nx"&gt;getProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;passengerDetails.data.driverInfo.currentVehicle.vehicleType&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reference &lt;br&gt;
&lt;a href="https://stackoverflow.com/a/64239231/11164153"&gt;https://stackoverflow.com/a/64239231/11164153&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Would be interested to learn if there is any other easier or better way. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Generate Different Background color based on ul depth using css variable</title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Sat, 13 Mar 2021 02:54:12 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/generate-different-background-color-based-on-ul-depth-using-css-variable-3dam</link>
      <guid>https://dev.to/jiteshdhamaniya/generate-different-background-color-based-on-ul-depth-using-css-variable-3dam</guid>
      <description>&lt;p&gt;So Recently i have come across a requirement where i had to create separate background-color based on ul deptt, i had html like this &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GYdijn3A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bh0o3rr2qkdjoelvd7w9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GYdijn3A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bh0o3rr2qkdjoelvd7w9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To do so i used two CSS Magical things. For Background color when we use &lt;em&gt;hsl&lt;/em&gt; to define a color we can control a color based on a number. like this &lt;/p&gt;




&lt;p&gt;background-color: hsl(100, 100%, 50%);&lt;/p&gt;




&lt;p&gt;HSL is literally stands for Hue, Saturation, Lightness, so does the parameters. So changing hue will change the color. &lt;/p&gt;

&lt;p&gt;Now second part is to figuring out dynamic number. Thanks to CSS variables we can define variables in css now. but i don't wanted to define hue number in css rather wanted to do using depth number which we can then convert to hue number using another css magic function which is calc. let me show you what i mean.&lt;/p&gt;




&lt;p&gt;html {&lt;br&gt;
     /* Define a variable &lt;em&gt;/&lt;br&gt;
     --depth:0;&lt;br&gt;
}&lt;br&gt;
ul {&lt;br&gt;
     /&lt;/em&gt; Define background color */&lt;br&gt;
     background-color:hsl(calc(100 + var(--depth, 1) * 40 ), 100%, 50%);&lt;br&gt;
}&lt;/p&gt;




&lt;p&gt;here calc returns &lt;strong&gt;&lt;em&gt;100&lt;/em&gt;&lt;/strong&gt; for &lt;strong&gt;&lt;em&gt;--depth:0&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;140&lt;/em&gt;&lt;/strong&gt; for &lt;strong&gt;&lt;em&gt;--depth:1&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now css part is done, in html we will override --depth variable value based on ul depth. &lt;/p&gt;

&lt;p&gt;so now html would look like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---Ob8fLFZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8seqd94rkgf7duefi38c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---Ob8fLFZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8seqd94rkgf7duefi38c.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;thats it. You will see different background colours all done in css. &lt;/p&gt;

&lt;p&gt;You can check working snippet here. &lt;br&gt;
&lt;a href="https://codepen.io/jiteshdhamaniya/pen/NWboMKZ"&gt;https://codepen.io/jiteshdhamaniya/pen/NWboMKZ&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me know if anyone does have better solution. See you next time. &lt;/p&gt;

&lt;p&gt;P.S. - was having hard time, formatting ul, li code here, hence did the images. &lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Create Family Tree with just CSS and HTML</title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Fri, 05 Mar 2021 07:01:25 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/create-family-tree-with-just-css-and-html-3l6k</link>
      <guid>https://dev.to/jiteshdhamaniya/create-family-tree-with-just-css-and-html-3l6k</guid>
      <description>&lt;p&gt;This is great. &lt;br&gt;
&lt;a href="https://codepen.io/ross-angus/pen/jwxMjL"&gt;https://codepen.io/ross-angus/pen/jwxMjL&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>Validate a local Variable in Laravel Livewire.</title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Mon, 01 Mar 2021 07:11:18 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/validate-a-local-variable-in-laravel-livewire-2a39</link>
      <guid>https://dev.to/jiteshdhamaniya/validate-a-local-variable-in-laravel-livewire-2a39</guid>
      <description>&lt;p&gt;Laravel LiveWire is a phenomenal framework for Laravel. Using it for 1 hour makes you fall in love with it. I use nowadays for any project i am doing in Laravel. Anyways recently i had to validate a variable which was not a public one. &lt;/p&gt;

&lt;p&gt;for Public variables its straightforward you define&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected $rules = []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or define&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected function rules(){
    return []
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then call $this-&amp;gt;validate(). Simple. &lt;/p&gt;

&lt;p&gt;But my requirement was to validate a variable which i was getting on click call &lt;code&gt;(wire.click)&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;&amp;lt;a wire:click="changeStatus({{ $row-&amp;gt;id }},4)"&amp;gt;Mark as Approve&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;little did i know Livewire does have solution for it as well for validating a local variable you do something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $validate = Validator::make(
            ['status' =&amp;gt; $status], // here you assign value for validation
            ['status' =&amp;gt; 'required|integer|min:1|max:2'],
            ['required' =&amp;gt; 'The :attribute field is required'],
        )-&amp;gt;validate();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is my complete code if you interested.&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 changeStatus($id, $status){
        $request = PayoutRequest::find($id);

        $validate = Validator::make(
            ['status' =&amp;gt; $status],
            ['status' =&amp;gt; 'required|integer|min:1|max:2'],
            ['required' =&amp;gt; 'The :attribute field is required'],
        )-&amp;gt;validate();

        $request-&amp;gt;status = $status;
        $request-&amp;gt;save();
        session()-&amp;gt;flash('status', "Status has been updated.");
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;hope this will help someone save some time. &lt;/p&gt;

</description>
      <category>laravel</category>
      <category>livewire</category>
    </item>
    <item>
      <title>Dispatch a job from tinker in Laravel</title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Thu, 31 Dec 2020 10:06:01 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/dispatch-a-job-from-tinker-in-laravel-13o7</link>
      <guid>https://dev.to/jiteshdhamaniya/dispatch-a-job-from-tinker-in-laravel-13o7</guid>
      <description>&lt;p&gt;When you need to dispatch job from tinker, the normal command which is&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;App\Jobs\YourJob::dispatch();&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;would not work in tinker because dispatch helper function depends on garbage collection. Hence to dispatch a job from tinker, use any of the following commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\Bus::dispatch(new App\Jobs\YourJob($someArgument));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\Queue::push(new App\Jobs\YourJob($someArgument)); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reference - &lt;a href="https://github.com/laravel/tinker/commit/1baadfe1721f85cd4e776aa323128dcd329f170d#diff-04c6e90faac2675aa89e2176d2eec7d8"&gt;https://github.com/laravel/tinker/commit/1baadfe1721f85cd4e776aa323128dcd329f170d#diff-04c6e90faac2675aa89e2176d2eec7d8&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>mysql</category>
      <category>webdev</category>
    </item>
    <item>
      <title>SQL Tip - Weird Behaviour of SUM or any operator When joining more than 2 tables</title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Sat, 05 Dec 2020 04:53:35 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/sql-tip-weird-behaviour-of-sum-or-any-operator-when-joining-more-than-2-tables-4b24</link>
      <guid>https://dev.to/jiteshdhamaniya/sql-tip-weird-behaviour-of-sum-or-any-operator-when-joining-more-than-2-tables-4b24</guid>
      <description>&lt;p&gt;When joining more than two tables and you want to do some operator thing such as SUM from one table column, you have to make sure joining table query return only one result, else you would find some weird behaviour such as concat instead of sum. &lt;/p&gt;

&lt;p&gt;Have a look on this query&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select sum(payments.amount), users.id, channels.channel_name , channels.channel_id from users
left join payments on payments.user_id = users.id 
left join channels on channels.user_id = users.id and channels.id = (select id from channels where channels.user_id = users.id limit 0,1) 
group by users.id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if i don't add&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;channels.id = (select id from channels where channels.user_id = users.id limit 0,1) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;when joining channels table, it might fetch more than one results of channels for that user and it would make sql to behave weirdly and it ends up concating &lt;code&gt;payments.amount&lt;/code&gt; instead of &lt;code&gt;sum(payments.amount)&lt;/code&gt;. &lt;/p&gt;

</description>
      <category>sql</category>
      <category>webdev</category>
      <category>mysql</category>
    </item>
    <item>
      <title>Advance Searching in Laravel for JSON Column type and using WHEN Method</title>
      <dc:creator>Jitesh Dhamaniya</dc:creator>
      <pubDate>Tue, 22 Sep 2020 06:23:50 +0000</pubDate>
      <link>https://dev.to/jiteshdhamaniya/advance-searching-in-laravel-for-json-column-type-and-when-method-3dp2</link>
      <guid>https://dev.to/jiteshdhamaniya/advance-searching-in-laravel-for-json-column-type-and-when-method-3dp2</guid>
      <description>&lt;p&gt;As a Regular Programmer Advance Searching is something you encounter once in a while. I recently implemented it in Laravel. Which i am going to explain here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisite&lt;/strong&gt;  - it’s assumed that you do have basic knowledge of Laravel Architecture and its functionality such as how model, controller and routing works. &lt;/p&gt;

&lt;p&gt;Okay so we do have a &lt;code&gt;biodata&lt;/code&gt; &lt;code&gt;table&lt;/code&gt; as the name represents it saves the biodata of a user. And this is how its migration looks like &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Migration&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;$table-&amp;gt;id();
$table-&amp;gt;enum('gender',['boy','girl']);
$table-&amp;gt;string('name',255);
$table-&amp;gt;json('biodata');
$table-&amp;gt;timestamps();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we do have a table column &lt;code&gt;biodata&lt;/code&gt; which is JSON type. This allows us to save JSON in our db. And we are going to use &lt;a href="https://laravel.com/docs/8.x/eloquent-mutators#array-and-json-casting"&gt;attribute casting&lt;/a&gt; to convert it to object automatically when fetching. So our Biodata model would look like this &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model&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;namespace App;

use Illuminate\Database\Eloquent\Model;

class Biodata extends Model
{
    protected $guarded = [];

    protected $casts = [
       'biodata' =&amp;gt; object
    ];

    protected $perPage = 10;

}

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

&lt;/div&gt;



&lt;p&gt;Now before going further let’s see what our Biodata object would look like &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Factory&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;return [
            'gender' =&amp;gt; $this-&amp;gt;faker-&amp;gt;randomElement($this-&amp;gt;gender),
            'name'=&amp;gt; $this-&amp;gt;faker-&amp;gt;name(),
            'biodata' =&amp;gt; [
                'personal'=&amp;gt;[
                    'qualification' =&amp;gt; $this-&amp;gt;faker-&amp;gt;randomElement($this-&amp;gt;qualification),
                    'height'=&amp;gt;$this-&amp;gt;faker-&amp;gt;randomElement($this-&amp;gt;height),
                    'income'=&amp;gt;$this-&amp;gt;faker-&amp;gt;numberBetween(100000,1000000),
                    'occupation' =&amp;gt; $this-&amp;gt;faker-&amp;gt;randomElement($this-&amp;gt;jobs),
                ],
                'family'=&amp;gt;[
                    'father_gotra' =&amp;gt; $this-&amp;gt;faker-&amp;gt;randomElement($this-&amp;gt;gotra),
                    'mother_gotra' =&amp;gt; $this-&amp;gt;faker-&amp;gt;randomElement($this-&amp;gt;gotra),
                ],
                'contact'=&amp;gt;[
                    'state' =&amp;gt; $this-&amp;gt;faker-&amp;gt;randomElement($this-&amp;gt;indianStates),
                ]
            ],
        ];

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

&lt;/div&gt;



&lt;p&gt;And on all these fields we are going to run a search. &lt;br&gt;
Now It’s time to discuss what we want to get out of our search function. So here our all optional search parameters  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Gender

&lt;ul&gt;
&lt;li&gt;Single Value&lt;/li&gt;
&lt;li&gt;field type - ENUM&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Qualification 

&lt;ul&gt;
&lt;li&gt;Could be Multiple Values &lt;/li&gt;
&lt;li&gt;field type - JSON Key&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Min Height 

&lt;ul&gt;
&lt;li&gt;Single Value
&lt;/li&gt;
&lt;li&gt;field type - JSON Key&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Income 

&lt;ul&gt;
&lt;li&gt;Single Value &lt;/li&gt;
&lt;li&gt;field type - JSON Key&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Occupation 

&lt;ul&gt;
&lt;li&gt;Single Value &lt;/li&gt;
&lt;li&gt;field type - JSON Key&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Gotra

&lt;ul&gt;
&lt;li&gt;Multiple Value &lt;/li&gt;
&lt;li&gt;field type - JSON Key&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now this might seem very straightforward to you, all you have to use is &lt;a href="https://laravel.com/docs/8.x/queries#where-clauses"&gt;&lt;code&gt;where&lt;/code&gt;&lt;/a&gt; statement and you should be okay BUT hold your horses and Let’s go over some obvious problems first&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Searching in JSON field ?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So how are we going to search in JSON ? well apparently that's not hard with MYSQL and even better with Laravel, in nutshell this is how you search in a JSON field provided its key&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return $query-&amp;gt;where('biodata-&amp;gt;personal-&amp;gt;income', '&amp;gt;=', $minIncome);

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

&lt;/div&gt;



&lt;p&gt;Check Biodata object above to understand. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Multiple Values &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now before jumping into code to write search function, the one question you might be asking is how you are supposed to send multiple values in a query string ? well glad you asked, we will simply add them with comma like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http:://url.com/?qualification=MBA,BA&amp;amp;gender=boy 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can simply explode them using “,” and it will give us an array of values for that parameter. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How to add multiple queries to where statements ? &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So this is a standard where statement from Laravel docs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB::table('users')-&amp;gt;where('votes', 100)-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we do have a better one too&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$users = DB::table('users')-&amp;gt;where([
    ['status', '=', '1'],
    ['subscribed', '&amp;lt;&amp;gt;', '1'],
])-&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you can add multiple arguments to where statement, &lt;br&gt;
But We need to have some kind of validation before we actually jump to running any query, Because all parameters are optional, so user might not provide all or any input to add to query. &lt;/p&gt;

&lt;p&gt;And hence we need to write extra code when searching with where and that’s where &lt;a href="https://laravel.com/docs/8.x/queries#conditional-clauses"&gt;&lt;code&gt;when&lt;/code&gt;&lt;/a&gt; comes to save us. This is what official documentation says about it &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sometimes you may want clauses to apply to a query only when something else is true. For instance you may only want to apply a where statement if a given input value is present on the incoming request. You may accomplish this using the when method:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And this is how you write it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$users = DB::table('users')
                -&amp;gt;when($role, function ($query, $role) {
                    return $query-&amp;gt;where('role_id', $role);
                })
                -&amp;gt;get();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But we have one more problem, how do we go about adding multiple values for the same parameter, well the second argument of when is a function and we can do anything in this function :) keep reading&lt;/p&gt;

&lt;p&gt;So for checking multiple values for the same parameter we are going to use a loop in it and this is how it's going to look like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-&amp;gt;when($gotra, function ($query, $gotra) {
               foreach($gotra as $g){
                   $query-&amp;gt;where('biodata-&amp;gt;family-&amp;gt;father_gotra', '&amp;lt;&amp;gt;' ,$g);
               }
               return $query;
           })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So that’s it. we covered all the basics we going to need to write search function. and this is how it’s going to look like&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 search(){

       $gender = request('gender');
       $state = request('state');

       $minIncome = (int)request('minIncome');
       $minHeight = (int)request('minHeight');

       $qualifications = request('qualification') != '' ? explode(",", request('qualification') ) : false;

       $gotra = request('gotra') != '' ? explode(",", request('gotra') ) : false;

       $results = Biodata::
           when($gender, function ($query, $gender) {
               return $query-&amp;gt;where('gender', $gender);
           })
           -&amp;gt;when($state, function ($query, $state) {
               return $query-&amp;gt;where('biodata-&amp;gt;contact-&amp;gt;state', $state);
           })
           -&amp;gt;when($qualifications, function ($query, $minQualification) {

               foreach($qualifications as $qualification){
                   $query-&amp;gt;where('biodata-&amp;gt;personal-&amp;gt;qualification', '=', $qualification);
               }
               return $query;

           })
           -&amp;gt;when($minIncome, function ($query, $minIncome) {
               return $query-&amp;gt;where('biodata-&amp;gt;personal-&amp;gt;income', '&amp;gt;=', $minIncome);
           })
           -&amp;gt;when($minHeight, function ($query, $minHeight) {
               return $query-&amp;gt;where('biodata-&amp;gt;personal-&amp;gt;height', '&amp;gt;=' , $minHeight);
           })
           -&amp;gt;when($gotra, function ($query, $gotra) {
               foreach($gotra as $g){
                   $query-&amp;gt;where('biodata-&amp;gt;family-&amp;gt;father_gotra', '&amp;lt;&amp;gt;' ,$g);
               }
               return $query;
           })
           -&amp;gt;paginate(10);

          return response($results,200);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I followed TDD approach while developing this so i created tests first, let me know if anyone of you want to check them out. Send me msg and i will share code. &lt;/p&gt;

&lt;p&gt;So i will leave you guys with this today, let me know what you think.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>webdev</category>
      <category>php</category>
      <category>mysql</category>
    </item>
  </channel>
</rss>
