<?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: John Wanjema</title>
    <description>The latest articles on DEV Community by John Wanjema (@wanjema).</description>
    <link>https://dev.to/wanjema</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%2F670956%2F481c1751-698a-4ad8-8e0b-03bec960e6db.png</url>
      <title>DEV Community: John Wanjema</title>
      <link>https://dev.to/wanjema</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wanjema"/>
    <language>en</language>
    <item>
      <title>Advanced Javascript Functions</title>
      <dc:creator>John Wanjema</dc:creator>
      <pubDate>Tue, 12 Oct 2021 09:49:26 +0000</pubDate>
      <link>https://dev.to/luxdevhq/advanced-working-with-functions-d0b</link>
      <guid>https://dev.to/luxdevhq/advanced-working-with-functions-d0b</guid>
      <description>&lt;h2&gt;
  
  
  What is a Javascript functions
&lt;/h2&gt;

&lt;p&gt;A function is a block of organized,reusable code that is used to perform a single,related action.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Working with Functions
&lt;/h2&gt;

&lt;p&gt;Function basics include function declarations,passing parameters and function scope.&lt;br&gt;
check out this article that cover into to Javascript functions.&lt;br&gt;
&lt;a href="https://dev.to/luxacademy/javascript-functions-257f"&gt;Javascript Functions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article we are going to discuss the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The new function&lt;/li&gt;
&lt;li&gt;Immediately invoked functions&lt;/li&gt;
&lt;li&gt;closures&lt;/li&gt;
&lt;li&gt;Arrow functions&lt;/li&gt;
&lt;li&gt;This keyword&lt;/li&gt;
&lt;li&gt;The call method&lt;/li&gt;
&lt;li&gt;The apply method&lt;/li&gt;
&lt;li&gt;The bind method&lt;/li&gt;
&lt;li&gt;Default parameters&lt;/li&gt;
&lt;li&gt;Rest parameters&lt;/li&gt;
&lt;li&gt;Spread parameters&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  The new function
&lt;/h2&gt;

&lt;p&gt;The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;Car&lt;span class="o"&gt;(&lt;/span&gt;make, model, year&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  this.make &lt;span class="o"&gt;=&lt;/span&gt; make&lt;span class="p"&gt;;&lt;/span&gt;
  this.model &lt;span class="o"&gt;=&lt;/span&gt; model&lt;span class="p"&gt;;&lt;/span&gt;
  this.year &lt;span class="o"&gt;=&lt;/span&gt; year&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

const car1 &lt;span class="o"&gt;=&lt;/span&gt; new Car&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'VW'&lt;/span&gt;, &lt;span class="s1"&gt;'GTI'&lt;/span&gt;, 2017&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

console.log&lt;span class="o"&gt;(&lt;/span&gt;car1.make&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; // VW
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Immediately Invoked Function Expression(IIFE)
&lt;/h3&gt;

&lt;p&gt;An IIFE Lets us group our code and have it work in isolation,independent of any other code.&lt;br&gt;
Invokes a function right away where its defined.&lt;br&gt;
This prevents functions and variables from polluting the global object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function &lt;/span&gt;hello&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    console.log&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hello World'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; //Hello
&lt;span class="o"&gt;})()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make it a function expression, we assign it to a variable or use it in another expression.&lt;/p&gt;

&lt;h3&gt;
  
  
  closures
&lt;/h3&gt;

&lt;p&gt;A closure is a feature in JavaScript where a function inner scope has access to the outer scope.&lt;br&gt;
In the example below closure help keep message within the scope and it can be accessed in the getMessage function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;let &lt;/span&gt;greeting &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;let &lt;/span&gt;message &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Hello'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;let &lt;/span&gt;getMessage &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;message&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        getMessage: getMessage
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;})()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

console.log&lt;span class="o"&gt;(&lt;/span&gt;greeting.message&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; //Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Arrow functions
&lt;/h3&gt;

&lt;p&gt;Arrow functions were introduced ES6.Refers to anonymous functions with their own unique syntax.Simpler way to create a function.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;shorter syntax&lt;/li&gt;
&lt;li&gt;this derives it value from  enclosing &lt;a href="https://en.wikipedia.org/wiki/Scope_(computer_science)" rel="noopener noreferrer"&gt;lexical scope&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Shortcomings.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; Arrow functions don't have their own this value.&lt;/li&gt;
&lt;li&gt;No argument object - we can't reference arguments
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;let &lt;/span&gt;greet &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Hello world'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;let &lt;/span&gt;message &lt;span class="o"&gt;=&lt;/span&gt; greet&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
console.log&lt;span class="o"&gt;(&lt;/span&gt;message&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; //Hello World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there is one parameter parenthesis are optional.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;let &lt;/span&gt;greet &lt;span class="o"&gt;=&lt;/span&gt; name &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Hello'&lt;/span&gt; + name&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  This keyword
&lt;/h3&gt;

&lt;p&gt;Refers to the owner of the function we are executing&lt;br&gt;
So if it's a standard function,this refers to the global window object;otherwise it can refer to the object that a function is a method of.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;let &lt;/span&gt;message &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    name: &lt;span class="s1"&gt;'john'&lt;/span&gt;,
    regularFunction&lt;span class="o"&gt;(&lt;/span&gt;name&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        console.log&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hello'&lt;/span&gt; + this.name&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;,

    arrowFunction: &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; console.log&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hi'&lt;/span&gt; + this.name&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

message.regularFunction&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; // Hello John
message.arrowFunction&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;// Hi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The call method
&lt;/h3&gt;

&lt;p&gt;The call() allows for a function/method belonging to one object to be assigned and called for a different object.&lt;br&gt;
call() provides a new value of this to the function/method. &lt;br&gt;
With call(), you can write a method once and then inherit it in another object, without having to rewrite the method for the new object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;let &lt;/span&gt;car1 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; brand: &lt;span class="s1"&gt;'Vw'&lt;/span&gt;, color: &lt;span class="s1"&gt;'blue'&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;let &lt;/span&gt;car2 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; brand: &lt;span class="s1"&gt;'Toyota'&lt;/span&gt;, color: &lt;span class="s1"&gt;'white'&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;let &lt;/span&gt;returnCarBrand &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    console.log&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Car brand is '&lt;/span&gt; + this.brand&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

returnCarBrand.call&lt;span class="o"&gt;(&lt;/span&gt;car1&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; // Car brand is Vw
returnCarBrand.call&lt;span class="o"&gt;(&lt;/span&gt;car2&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; // Car brand is Toyota
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The apply method
&lt;/h3&gt;

&lt;p&gt;The apply() method calls a function with a given this value, and arguments provided as an array.&lt;br&gt;
Same syntax as call difference is that call accepts an argument list, while apply accepts a single array of arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;bookTitle&lt;span class="o"&gt;(&lt;/span&gt;name, author&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    console.log&lt;span class="o"&gt;(&lt;/span&gt;name + &lt;span class="s1"&gt;'is written by '&lt;/span&gt; + author&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    console.log&lt;span class="o"&gt;(&lt;/span&gt;this&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
bookTitle.apply&lt;span class="o"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'HTML &amp;amp; CSS: Design and Build Web Sites'&lt;/span&gt;, &lt;span class="s1"&gt;'Jon Duckett'&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The bind method
&lt;/h3&gt;

&lt;p&gt;Allows to make a copy of a function and then change the value of this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;let &lt;/span&gt;book &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    author: &lt;span class="s1"&gt;'Mary'&lt;/span&gt;,
    getAuthor: &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;this.author&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;let &lt;/span&gt;book2 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; author: &lt;span class="s1"&gt;'John'&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;let &lt;/span&gt;getAuthorcopy &lt;span class="o"&gt;=&lt;/span&gt; book.getAuthor.bind&lt;span class="o"&gt;(&lt;/span&gt;book2&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
console.log&lt;span class="o"&gt;(&lt;/span&gt;getAuthorcopy&lt;span class="o"&gt;())&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; // John
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Default parameters
&lt;/h3&gt;

&lt;p&gt;Allow named parameters to be initialized with default values if no value or undefined is passed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;sayHi&lt;span class="o"&gt;(&lt;/span&gt;message, name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'John'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    console.log&lt;span class="o"&gt;(&lt;/span&gt;message + name&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rest parameters
&lt;/h3&gt;

&lt;p&gt;The rest parameter syntax allows a function to accept an indefinite number of arguments as an array.&lt;br&gt;
Rest parameters should always come after regular parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;let &lt;/span&gt;sayHi &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;function &lt;/span&gt;greet&lt;span class="o"&gt;(&lt;/span&gt;...names&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    names.forEach&lt;span class="o"&gt;(&lt;/span&gt;name &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; console.log&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hi '&lt;/span&gt; + name&lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
greet&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Welcome'&lt;/span&gt;, &lt;span class="s1"&gt;'John'&lt;/span&gt;, &lt;span class="s1"&gt;'Mary'&lt;/span&gt;, &lt;span class="s1"&gt;'James'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; // Hi John // Hi Mary // Hi James
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Spread Operator
&lt;/h3&gt;

&lt;p&gt;Allows an a function to take an array as an argument and spread out its elements so that they can be assigned  to individual parameters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;greet&lt;span class="o"&gt;(&lt;/span&gt;user1, user2&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    console.log&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hello'&lt;/span&gt; + user1 +&lt;span class="s1"&gt;' and '&lt;/span&gt; + user2&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;let &lt;/span&gt;names &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'John'&lt;/span&gt;,&lt;span class="s1"&gt;'Mary'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
greet&lt;span class="o"&gt;(&lt;/span&gt;...names&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; //Hello John and Mary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Getting started with Laravel and Vue js</title>
      <dc:creator>John Wanjema</dc:creator>
      <pubDate>Fri, 01 Oct 2021 08:15:58 +0000</pubDate>
      <link>https://dev.to/wanjema/getting-started-with-laravel-and-vue-js-2hc6</link>
      <guid>https://dev.to/wanjema/getting-started-with-laravel-and-vue-js-2hc6</guid>
      <description>&lt;h2&gt;
  
  
  Ever wondered how to setup Vue in your laravel project.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmtm25h4rb9sgsw3505z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmtm25h4rb9sgsw3505z.png" alt="laravel and vue js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Laravel
&lt;/h2&gt;

&lt;p&gt;Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.&lt;br&gt;
Here is a link to their Documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://laravel.com/docs/8.x" rel="noopener noreferrer"&gt;Laravel&lt;/a&gt;
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Vue
&lt;/h2&gt;

&lt;p&gt;Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.&lt;br&gt;
Here is the link to their documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;Vue js&lt;/a&gt;
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Why use Laravel with Vue
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Streamline the Development Process
&lt;/h3&gt;

&lt;p&gt;This structure allows for one to be a full stack developer within a single project&lt;/p&gt;

&lt;h3&gt;
  
  
  Single-Page Application Development
&lt;/h3&gt;

&lt;p&gt;Both Vue js and Laravel support single page applications.This allows the application assets get loaded once, all that your application does as the user engages with it is request data which typically requires low bandwidth to fulfill.&lt;/p&gt;

&lt;h3&gt;
  
  
  Building Optimal Complex Front-end Pages
&lt;/h3&gt;

&lt;p&gt;With Vuejs a developer does not need to use jquery to manipulate blade templates.Vue allows for easier managment of DOM using a virtual Dom.&lt;/p&gt;

&lt;h3&gt;
  
  
  Easy to Learn and Use
&lt;/h3&gt;

&lt;p&gt;Both Laravel and Vue have a robust documentation that is easy to learn and integrate.&lt;/p&gt;

&lt;h3&gt;
  
  
  First ensure that Laravel is installed.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Here is link to install Laravel if you haven't.
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;a href="https://laravel.com/docs/8.x/installation" rel="noopener noreferrer"&gt;Laravel 8 Installation&lt;/a&gt;
&lt;/h4&gt;

&lt;h2&gt;
  
  
  Create a laravel project
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer create-project laravel/laravel laravel-vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scaffolding Vue js
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install laravel/ui package
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require laravel/ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install the frontend scaffolding using the ui Artisan command
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Basic scaffolding
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan ui vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Generate Auth scaffolding.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan ui vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Compile your fresh scaffolding.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure Blade
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Import app.js and add app id
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;doctype html&amp;gt;
&amp;lt;html &lt;span class="nv"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"{{ str_replace('_', '-', app()-&amp;gt;getLocale()) }}"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;&lt;span class="nb"&gt;head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;meta &lt;span class="nv"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"utf-8"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;meta &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"viewport"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; CSRF Token &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;meta &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"csrf-token"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"{{ csrf_token() }}"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;title&amp;gt;Laravel Vue&amp;lt;/title&amp;gt;
    &amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; Scripts &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;script &lt;span class="nv"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"{{ asset('js/app.js') }}"&lt;/span&gt; defer&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; Fonts &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;&lt;span class="nb"&gt;link &lt;/span&gt;&lt;span class="nv"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"dns-prefetch"&lt;/span&gt; &lt;span class="nv"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"//fonts.gstatic.com"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;&lt;span class="nb"&gt;link &lt;/span&gt;&lt;span class="nv"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://fonts.googleapis.com/css?family=Nunito"&lt;/span&gt; &lt;span class="nv"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"stylesheet"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt; Styles &lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &amp;lt;&lt;span class="nb"&gt;link &lt;/span&gt;&lt;span class="nv"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"{{ asset('css/app.css') }}"&lt;/span&gt; &lt;span class="nv"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"stylesheet"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"app"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &amp;lt;main &lt;span class="nv"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"py-3"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &amp;lt;h3&amp;gt;Laravel Vue&amp;lt;/h3&amp;gt;
            &amp;lt;router-view&amp;gt;&amp;lt;/router-view&amp;gt;
        &amp;lt;/main&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add Vue components
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Add new vue.js file in resources/js/components called app.vue and add the following code.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
    &amp;lt;div&amp;gt;
        &lt;span class="o"&gt;{{&lt;/span&gt;message&lt;span class="o"&gt;}}&lt;/span&gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;
&amp;lt;script&amp;gt;
&lt;span class="nb"&gt;export &lt;/span&gt;default &lt;span class="o"&gt;{&lt;/span&gt;
    data&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            message: &lt;span class="s1"&gt;'Hello World'&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setup Vue router
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install Vue router
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install vue-router --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create a routes folder and add a home.js file.Add the following code.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const home = () =&amp;gt;import ( '../components/app.vue')

export default [
    {
        path: '/home',
        component: home,
        name: 'home',
    },
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Head over to the resources/js folder and create a file called routes.js and add the following code.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Vue from 'vue'
import VueRouter from 'vue-router'
import home from './routes/home';

Vue.use(VueRouter);
export default new VueRouter({
    mode: 'history',
    scrollBehavior: (to, from, savedPosition) =&amp;gt; ({ y: 0 }), 
    routes: [
        ...home,
    ],
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add routes to app.js
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Replace the code in your resources/js/app.js with the code below.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require('./bootstrap');
require('../sass/app.scss')
import Vue from 'vue'

window.Vue = require('vue');

// router
import router from './routes.js';
window.router = router;
window.Fire = new Vue();

const app = new Vue({
    el: '#app',
    router,
}).$mount('#app');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setup Laravel routes
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Update Laravel routes in web.php
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::get('/{any?}', [
    function () {
        return view('welcome');
    }
])-&amp;gt;where('any', '.*');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run the application
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Start Laravel app
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compile components
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Access the application at localhost:8000
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Open &lt;a href="http://localhost:8000/" rel="noopener noreferrer"&gt;localhost:8000&lt;/a&gt;
&lt;/h4&gt;

&lt;h3&gt;
  
  
  Link to Github repo.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/johnwanjema/Getting-startes-with-Laravel-and-Vue-js" rel="noopener noreferrer"&gt;Github repository&lt;/a&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Happy coding
&lt;/h3&gt;

</description>
      <category>laravel</category>
      <category>vue</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
