<?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: mohamed benhida</title>
    <description>The latest articles on DEV Community by mohamed benhida (@simo_benhida).</description>
    <link>https://dev.to/simo_benhida</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%2F52904%2F559696fc-bad9-47e7-aef2-23a0217a21dd.png</url>
      <title>DEV Community: mohamed benhida</title>
      <link>https://dev.to/simo_benhida</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/simo_benhida"/>
    <language>en</language>
    <item>
      <title>TIP - Import Vuejs Modules at once.</title>
      <dc:creator>mohamed benhida</dc:creator>
      <pubDate>Fri, 16 Mar 2018 21:48:47 +0000</pubDate>
      <link>https://dev.to/simo_benhida/tip---import-vuejs-modules-at-once-58dl</link>
      <guid>https://dev.to/simo_benhida/tip---import-vuejs-modules-at-once-58dl</guid>
      <description>&lt;p&gt;Hey in this Post We will see how can we add multiple &lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;Vuejs&lt;/a&gt; modules at once.&lt;/p&gt;

&lt;p&gt;We all needed to import modules each time we create one on our modules folder like this (is from a real world project).&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;store/index.js&lt;/em&gt;&lt;/span&gt;&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;Vue&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vue&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;Vuex&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vuex&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;auth&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./modules/auth&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;rows&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./modules/rows&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;rooms&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./modules/rooms&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;students&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./modules/students&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;rooms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;students&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;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimage.ibb.co%2FbAWG4c%2FScreen_Shot_2018_03_16_at_8_54_22_PM.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%2Fimage.ibb.co%2FbAWG4c%2FScreen_Shot_2018_03_16_at_8_54_22_PM.png" title="vuejs" alt="Vuejs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like you see in the example above we have a 10 extra lines in our code. 5 lines to import the modules and 5 others to declare them on modules object.&lt;/p&gt;

&lt;p&gt;Let's see now how can we reduce this 10 lines to 1 line So to do that we need to create an &lt;code&gt;index.js&lt;/code&gt; file on modules folder that can listen to all the &lt;code&gt;.js&lt;/code&gt; files inside modules folder and import them one by one.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;modules/index.js&lt;/em&gt;&lt;/span&gt;&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;camelCase&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lodash/camelCase&lt;/span&gt;&lt;span class="dl"&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;requireModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;context&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;js$/&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//extract js files inside modules folder&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;modules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

    &lt;span class="nx"&gt;requireModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fileName&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fileName&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./index.js&lt;/span&gt;&lt;span class="dl"&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="c1"&gt;//reject the index.js file&lt;/span&gt;

      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;moduleName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;camelCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;(\.\/&lt;/span&gt;&lt;span class="sr"&gt;|&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;js&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;/g&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="c1"&gt;//&lt;/span&gt;

      &lt;span class="nx"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;moduleName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;requireModule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;span&gt;&lt;em&gt;modules/auth.js&lt;/em&gt;&lt;/span&gt;&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;auth&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../api/auth&lt;/span&gt;&lt;span class="dl"&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;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;token&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;getters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;isLoggedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoggedIn&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;loginUser&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;commit&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;data&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="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;token&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;access_token&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;loginUser&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="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;registerUser&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;commit&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;token&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;access_token&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;loginUser&lt;/span&gt;&lt;span class="dl"&gt;"&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;data&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;async&lt;/span&gt; &lt;span class="nf"&gt;logoutUser&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;commit&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="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;logout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;token&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;logoutUser&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="p"&gt;};&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mutations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;loginUser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoggedIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;logoutUser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoggedIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;getters&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we go back to our &lt;code&gt;store/index.js&lt;/code&gt; and just import &lt;code&gt;"./modules"&lt;/code&gt; equivalent to &lt;code&gt;"./modules/index.js"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;store/index.js&lt;/em&gt;&lt;/span&gt;&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;Vue&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vue&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;Vuex&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vuex&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;modules&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./modules&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="nx"&gt;modules&lt;/span&gt; &lt;span class="c1"&gt;// Equivalent to =&amp;gt; modules : modules(imported)&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 see now how our store/index.js is clean.&lt;/p&gt;

&lt;p&gt;For more informations check &lt;a href="https://github.com/chrisvfritz/vue-enterprise-boilerplate/tree/master/src/state" rel="noopener noreferrer"&gt;chris vfritz repo&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>laravel</category>
    </item>
    <item>
      <title>The Magic Laravel Helper tap()</title>
      <dc:creator>mohamed benhida</dc:creator>
      <pubDate>Thu, 01 Mar 2018 21:12:03 +0000</pubDate>
      <link>https://dev.to/simo_benhida/the-magic-laravel-helper-tap--1jc7</link>
      <guid>https://dev.to/simo_benhida/the-magic-laravel-helper-tap--1jc7</guid>
      <description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;In this post we will talk about how &lt;code&gt;tap()&lt;/code&gt; helper works and where can we used in our projects.&lt;/p&gt;

&lt;p&gt;First of all, let's talk about what &lt;code&gt;tap()&lt;/code&gt; exactly do behind the scenes.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
function tap($value, $callback = null)
    {
        if (is_null($callback)) {
            return new HigherOrderTapProxy($value);
        }

        $callback($value);

        return $value;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span&gt;After using &lt;code&gt;tap()&lt;/code&gt; you must know that the very first thing we pass it is always what is going to be returned to us.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Let's work with an example so we can more see the differences. for now let's say the &lt;code&gt;$callback&lt;/code&gt; is not null and our &lt;code&gt;tap()&lt;/code&gt; helper is like that.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
function tap($value, $callback)
    {
        $callback($value);

        return $value;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Our example is that we want to update an user and in the same return the edited &lt;code&gt;$user&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
public function update(Request $request,User $user)
{
   $user = $user-&amp;gt;update($param);//return boolean
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We all know that &lt;code&gt;update()&lt;/code&gt; returns &lt;code&gt;boolean&lt;/code&gt; but we want it to return our edited &lt;code&gt;$user&lt;/code&gt; so we can pass it to our json response for example.Here come the rule of &lt;code&gt;tap()&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
public function update(Request $request,User $user)
  {
     $user = tap($user,function($user) use($request){
         $user-&amp;gt;update($request-&amp;gt;all());
        }); //returns Edited User
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We passed &lt;code&gt;$user&lt;/code&gt; and a &lt;code&gt;closure&lt;/code&gt; that accept &lt;code&gt;$user&lt;/code&gt; and runs &lt;code&gt;update()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;the &lt;code&gt;$callback($value);&lt;/code&gt; will be triggered and it will returns the &lt;code&gt;$value&lt;/code&gt; at the end in our case it returns &lt;code&gt;$user&lt;/code&gt; model.&lt;/p&gt;

&lt;p&gt;But this is not helpfull it looks disgusting because we need to passe $request to closure and adding extra two lines.&lt;/p&gt;

&lt;p&gt;so here comes the rule of a nulled &lt;code&gt;$callback&lt;/code&gt; that will return a &lt;code&gt;new HigherOrderTapProxy($value);&lt;/code&gt; that helps us solve the problem above.&lt;/p&gt;

&lt;p&gt;Let's understand together what &lt;code&gt;HigherOrderTapProxy($value)&lt;/code&gt; really does.&lt;/p&gt;

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

namespace Illuminate\Support;

class HigherOrderTapProxy
{

    public $target;

    public function __construct($target)
    {
        $this-&amp;gt;target = $target; //target in our case is $user model
    }

    //when we call a method it will trigger this function
    public function __call($method, $parameters) 
    {
        $this-&amp;gt;target-&amp;gt;{$method}(...$parameters); //$user-&amp;gt;update($parameters)

        return $this-&amp;gt;target; //return $user;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Like we see &lt;code&gt;HigherOrderTapProxy&lt;/code&gt; class accept &lt;code&gt;$value&lt;/code&gt; and each time we call a method inside this class it will trigger the &lt;code&gt;__call()&lt;/code&gt; function then the method will apply to the &lt;code&gt;$value&lt;/code&gt; passed then it will return it.&lt;/p&gt;

&lt;p&gt;like you see in the comments above. now if you really understand how &lt;code&gt;HigherOrderTapProxy&lt;/code&gt; works you can just do this and it will works.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
public function update(Request $request,User $user)
 {
   $user = tap($user)-&amp;gt;update($request-&amp;gt;all());//return edited $user
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and here we have the same value with a code on one line.&lt;/p&gt;

&lt;p&gt;I hope your enjoyed reading this article.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
    </item>
    <item>
      <title>Reference And Copying Objects &amp; Arrays in Javascript</title>
      <dc:creator>mohamed benhida</dc:creator>
      <pubDate>Sat, 03 Feb 2018 23:48:54 +0000</pubDate>
      <link>https://dev.to/simo_benhida/reference-and-copying-objetcs--arrays-in-javascript-2h23</link>
      <guid>https://dev.to/simo_benhida/reference-and-copying-objetcs--arrays-in-javascript-2h23</guid>
      <description>&lt;p&gt;We all faced that error when we want to copy an array or an object to a new variable we end up changing the original variable when we update the new one.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;&lt;strong&gt;Arrays&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;So in this example we  have an &lt;code&gt;array&lt;/code&gt; variable&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let array = ["John","Doe","Alex"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;we create a new variable &lt;code&gt;array1&lt;/code&gt; that takes the value of &lt;code&gt;array&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let array1 = array

console.log(array1)
//["John", "Doe", "Alex"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now if we modified the &lt;code&gt;array1[2]&lt;/code&gt; for example &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array1[2] = "David"

console.log(array1)
//["John", "Doe", "David"]

console.log(array)
//["John", "Doe", "David"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fimage.ibb.co%2Fmded9R%2FScreen_Shot_2018_02_03_at_10_47_43_PM.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%2Fimage.ibb.co%2Fmded9R%2FScreen_Shot_2018_02_03_at_10_47_43_PM.png" title="devma" alt="devma"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We notice that if we change the array1 our original array get changed too.&lt;/p&gt;

&lt;p&gt;So to prevent that we have a mutiple methods :&lt;/p&gt;

&lt;p&gt;-&amp;gt; We could use ES6&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let array = ["John","Doe","Alex"]

let array1 = [...array]

array1[2] = "David"

console.log(array1)
//["John","Doe","David"]

console.log(array)
//["John","Doe","Alex"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fimage.ibb.co%2FeDm3b6%2FScreen_Shot_2018_02_03_at_10_55_55_PM.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%2Fimage.ibb.co%2FeDm3b6%2FScreen_Shot_2018_02_03_at_10_55_55_PM.png" title="devma" alt="devma"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; array.slice()&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let array2 = array.slice()

console.log(array2)
//["John","Doe","David"]

console.log(array)
//["John","Doe","Alex"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fimage.ibb.co%2FmCpZim%2FScreen_Shot_2018_02_03_at_10_59_46_PM.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%2Fimage.ibb.co%2FmCpZim%2FScreen_Shot_2018_02_03_at_10_59_46_PM.png" title="devma" alt="devma"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; [].concat(array)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let array3 = [].concat(array)

console.log(array3)
//["John","Doe","David"]

console.log(array)
//["John","Doe","Alex"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fimage.ibb.co%2FmJ4Zim%2FScreen_Shot_2018_02_03_at_11_02_25_PM.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%2Fimage.ibb.co%2FmJ4Zim%2FScreen_Shot_2018_02_03_at_11_02_25_PM.png" title="devma" alt="devma"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you know how can you deal with arrays let see about objets.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;span&gt;&lt;strong&gt;Objetcs&lt;/strong&gt;&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let object = { name:"John",age:23 }

let object1 = object

console.log(object1)

//{name: "John", age: 23}
object1.age = 23

console.log(object1)
//{name: "John", age: 23}

console.log(object)
//{name: "John", age: 23}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fimage.ibb.co%2Fj37LOm%2FScreen_Shot_2018_02_03_at_11_05_18_PM.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%2Fimage.ibb.co%2Fj37LOm%2FScreen_Shot_2018_02_03_at_11_05_18_PM.png" title="devma" alt="devma"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We found the same error as the arrays if we change the new var it changes the original one too.&lt;/p&gt;

&lt;p&gt;So let's find out how can we fix this with objects.&lt;/p&gt;

&lt;p&gt;We could use &lt;code&gt;Object.assign({},object)&lt;/code&gt; we pass our existing object to an empty one.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let object = { name:"John",age:23 }

let object2 = Object.assign({},object)

console.log(object2)

//{name: "John", age: 23}

object2.age = 12

console.log(object2)
//{name: "John", age: 12}

console.log(object)
//{name: "John", age: 23}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fimage.ibb.co%2FdjLUG6%2FScreen_Shot_2018_02_03_at_11_09_30_PM.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%2Fimage.ibb.co%2FdjLUG6%2FScreen_Shot_2018_02_03_at_11_09_30_PM.png" title="devma" alt="devma"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But is not all working fine if we add a second object inside the first one we will have the same error like this&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let object = {person : { name:"John",age:23 } }

let object3 = Object.assign({},object)

console.log(object3)

//{person : { name:"John",age:23 } }

object3.person.name = "Doe"

console.log(object3)
//{person : { name:"Doe",age:23 } }

console.log(object)
//{person : { name:"Doe",age:23 } }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fimage.ibb.co%2FjDYo9R%2FScreen_Shot_2018_02_03_at_11_13_53_PM.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%2Fimage.ibb.co%2FjDYo9R%2FScreen_Shot_2018_02_03_at_11_13_53_PM.png" title="devma" alt="devma"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we need to make a better is solution we convert the object to string then we parse it again using &lt;code&gt;JSON.parse(JSON.stringify(object))&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let object = { person : { name : "John" , age : 23 }}

let object4 = JSON.parse(JSON.stringify(object))

console.log(object4)
//{person : { name:"John",age:23 } }

object4.person.name = "Doe"

console.log(object4)
//{person : { name:"Doe",age:23 } }

console.log(object)
//{person : { name:"John",age:23 } }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fimage.ibb.co%2FnbJc3m%2FScreen_Shot_2018_02_03_at_11_18_46_PM.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%2Fimage.ibb.co%2FnbJc3m%2FScreen_Shot_2018_02_03_at_11_18_46_PM.png" title="devma" alt="devma"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading this post. Thanks For Reading&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>AutoComplete Searching With Javascript</title>
      <dc:creator>mohamed benhida</dc:creator>
      <pubDate>Thu, 18 Jan 2018 20:38:03 +0000</pubDate>
      <link>https://dev.to/simo_benhida/autocomplete-searching-with-javascript-de6</link>
      <guid>https://dev.to/simo_benhida/autocomplete-searching-with-javascript-de6</guid>
      <description>&lt;p&gt;Hey,&lt;/p&gt;

&lt;p&gt;In this post we will talk about autosearching with using only javascript no frameworks, we will need to fetch the data from the server so we will use Laravel for this.&lt;/p&gt;

&lt;p&gt;Our example is we want to search for &lt;em&gt;contacts&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;so we need to create a &lt;em&gt;Contact&lt;/em&gt; Model &lt;code&gt;php artisan make:model Contact -m &lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then go to &lt;span&gt;&lt;em&gt;database/factories/ModelFactory.php&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$factory-&amp;gt;define(App\Contact::class, function (Faker\Generator $faker)
{
    return [
        'name'    =&amp;gt; $faker-&amp;gt;name,
        'email'   =&amp;gt; $faker-&amp;gt;unique()-&amp;gt;safeEmail,
        'company' =&amp;gt; $faker-&amp;gt;sentence,
        'state'   =&amp;gt; $faker-&amp;gt;state,
    ];
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;after we create our migration table and we migrate using this command &lt;code&gt;php artisan migrate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;we can now create our fake data in our console with &lt;code&gt;php artisan tinker&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then we create 50 fake contacts using this command &lt;code&gt;factory(App\Contact::class,50)-&amp;gt;create();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;we create a link for this data&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;span&gt;routes/web.php&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::get('/contacts', function ()
{
    return App\Contact::all();
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;now we create our view&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;autosearching.blade.php&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;AutoSearch&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"
          integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body class="bg-light"&amp;gt;
&amp;lt;div class="container" style="margin-top : 10%"&amp;gt;
    &amp;lt;div class="row justify-content-center"&amp;gt;
        &amp;lt;div class="col-4"&amp;gt;
            &amp;lt;div class="bg-white"&amp;gt;
                &amp;lt;div class="input-group mb-3"&amp;gt;
                    &amp;lt;input type="text" placeholder="Searching ..." class="form-control input-search"&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div class="search"&amp;gt;

                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

const input = document.querySelector('.input-search');

input.addEventListener('click',EnableArray);
input.addEventListener('keyup',EnableArray);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fimage.ibb.co%2FjLk6bb%2FScreen_Shot_2018_01_03_at_8_20_35_PM.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%2Fimage.ibb.co%2FjLk6bb%2FScreen_Shot_2018_01_03_at_8_20_35_PM.png" title="searching" alt="searching"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First of all with our javascript code we need to extract data from the contacts link&lt;/p&gt;

&lt;p&gt;we use the new &lt;code&gt;fetch&lt;/code&gt; method that return &lt;code&gt;promise&lt;/code&gt; like &lt;code&gt;axios&lt;/code&gt; if you ever use it. you can learn more about fetch &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const api = '/contacts';
const contacts = [];

fetch(api)
   .then(response =&amp;gt; response.json())
   .then(blob =&amp;gt; contacts.push(...blob));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;then we need a method that can filter the contacts and get the one that resembles of the value we tape&lt;/p&gt;

&lt;p&gt;we work with regex for the &lt;code&gt;'gi'&lt;/code&gt; &lt;span&gt;-g&lt;/span&gt; is for global and &lt;span&gt;-i&lt;/span&gt; like upercase and lowercase are the same.&lt;/p&gt;

&lt;p&gt;the value that we search is the name and the email&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Searching(word) {
        return contacts.filter(contact =&amp;gt; {
            const regex = new RegExp(word,'gi')
            return contact.name.match(regex) || contact.email.match(regex);
        });
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we add some events to our input we need the click event and also the keyup change event.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const input = document.querySelector('.input-search');
input.addEventListener('click',EnableArray);
input.addEventListener('keyup',EnableArray);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Finally the &lt;code&gt;EnableArray&lt;/code&gt; that will inner the html on our empty div&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function EnableArray() {
        const matches = Searching(this.value);
        const html = matches.map(match =&amp;gt; {
            return ` &amp;lt;p class="p-2 d-flex flex-column border-bottom"&amp;gt;
                        &amp;lt;span&amp;gt;&amp;lt;small&amp;gt;${match.name}&amp;lt;/small&amp;gt;&amp;lt;small class="float-right"&amp;gt;From ${match.state}&amp;lt;/small&amp;gt;&amp;lt;/span&amp;gt;
                        &amp;lt;span&amp;gt;&amp;lt;small&amp;gt;${match.email}&amp;lt;/small&amp;gt;&amp;lt;/span&amp;gt;
                        &amp;lt;span&amp;gt;&amp;lt;small&amp;gt;${match.company}&amp;lt;/small&amp;gt;&amp;lt;/span&amp;gt;
                        &amp;lt;/p&amp;gt;
                        &amp;lt;hr&amp;gt;
                    `;
        }).join('');
        search.innerHTML = html;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimage.ibb.co%2FgC6Jpw%2FScreen_Shot_2018_01_03_at_8_30_58_PM.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%2Fimage.ibb.co%2FgC6Jpw%2FScreen_Shot_2018_01_03_at_8_30_58_PM.png" title="search" alt="search"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;autosearching.blade.php&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;If you dont want to follow all the steps there is the the full html file you can copy it directly&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;AutoSearch&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css"
          integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body class="bg-light"&amp;gt;
&amp;lt;div class="container" style="margin-top : 10%"&amp;gt;
    &amp;lt;div class="row justify-content-center"&amp;gt;
        &amp;lt;div class="col-4"&amp;gt;
            &amp;lt;div class="bg-white"&amp;gt;
                &amp;lt;div class="input-group mb-3"&amp;gt;
                    &amp;lt;input type="text" placeholder="Searching ..." class="form-control input-search"&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div class="search"&amp;gt;

                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;script&amp;gt;
    const api = '/contacts';
    const input = document.querySelector('.input-search');
    const search = document.querySelector('.search');
    const container = document.querySelector('.container');
    const contacts = [];

    fetch(api)
        .then(response =&amp;gt; response.json())
        .then(blob =&amp;gt; contacts.push(...blob));

    function Searching(word) {
        return contacts.filter(contact =&amp;gt; {
            const regex = new RegExp(word,'gi')
            return contact.name.match(regex) || contact.email.match(regex);
        });
    }

    function EnableArray() {
        const matches = Searching(this.value);
        const html = matches.map(match =&amp;gt; {
            return ` &amp;lt;p class="p-2 d-flex flex-column border-bottom"&amp;gt;
                        &amp;lt;span&amp;gt;&amp;lt;small&amp;gt;${match.name}&amp;lt;/small&amp;gt;&amp;lt;small class="float-right"&amp;gt;From ${match.state}&amp;lt;/small&amp;gt;&amp;lt;/span&amp;gt;
                        &amp;lt;span&amp;gt;&amp;lt;small&amp;gt;${match.email}&amp;lt;/small&amp;gt;&amp;lt;/span&amp;gt;
                        &amp;lt;span&amp;gt;&amp;lt;small&amp;gt;${match.company}&amp;lt;/small&amp;gt;&amp;lt;/span&amp;gt;
                        &amp;lt;/p&amp;gt;
                        &amp;lt;hr&amp;gt;
                    `;
        }).join('');
        search.innerHTML = html;
    }

    input.addEventListener('click',EnableArray);
    input.addEventListener('keyup',EnableArray);

    container.addEventListener('click',function() {
        search.innerHTML = ''
    });
&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
