<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Chandresh Singh</title>
    <description>The latest articles on Forem by Chandresh Singh (@chandreshhere).</description>
    <link>https://forem.com/chandreshhere</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%2F146850%2Fd6f1cc9a-d0d6-45fe-aa80-c093caf0ed34.jpg</url>
      <title>Forem: Chandresh Singh</title>
      <link>https://forem.com/chandreshhere</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chandreshhere"/>
    <language>en</language>
    <item>
      <title>Create your first Laravel Project on Docker using Laravel Sail</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Mon, 22 Feb 2021 08:31:08 +0000</pubDate>
      <link>https://forem.com/chandreshhere/create-your-first-laravel-project-on-docker-using-laravel-sail-52hk</link>
      <guid>https://forem.com/chandreshhere/create-your-first-laravel-project-on-docker-using-laravel-sail-52hk</guid>
      <description>&lt;p&gt;There are multiple ways to develop and run Laravel project on your system but here is the easiest way to create your Laravel project on docker using Laravel Sail which is a light weight command line interface for interacting with Laravel's docker configuration.&lt;/p&gt;

&lt;p&gt;All you need to do is install docker on your system, you can use either Docker cli or Docker Desktop and rest of the thing are all taken care by Laravel Sail.&lt;/p&gt;

&lt;p&gt;Before we start, if you want then you can also watch this tutorial.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/hcPQV3QymU8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's Start! &lt;/p&gt;

&lt;p&gt;To install Docker Desktop, &lt;a href="https://www.docker.com/products/docker-desktop"&gt;Click here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After Docker is installed and running, run the following command to create a new Laravel Project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-s&lt;/span&gt; https://laravel.build/example-app | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After your project is created, go inside your application directory and start &lt;strong&gt;Laravel Sail&lt;/strong&gt;.&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;cd &lt;/span&gt;example-app

./vendor/bin/sail up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once done, You can access your application at &lt;a href="http://localhost"&gt;http://localhost&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can execute all your commands like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./vendor/bin/sail php &lt;span class="nt"&gt;--version&lt;/span&gt;

./vendor/bin/sail node &lt;span class="nt"&gt;--version&lt;/span&gt;

./vendor/bin/sail php artisan list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also create an alias for sail if you don't want to type &lt;strong&gt;vendor/bin/sail&lt;/strong&gt; repeatedly.&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;alias &lt;/span&gt;&lt;span class="nv"&gt;sail&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'bash vendor/bin/sail'&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Then you can execute your commands like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sail php &lt;span class="nt"&gt;--version&lt;/span&gt;

sail node &lt;span class="nt"&gt;--version&lt;/span&gt;

sail php artisan list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To stop all your containers, you can type &lt;strong&gt;Ctrl+C&lt;/strong&gt; or you can also use &lt;strong&gt;sail down&lt;/strong&gt; command.&lt;/p&gt;

&lt;p&gt;Hope you find this useful.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>sail</category>
      <category>docker</category>
    </item>
    <item>
      <title>Beginner's Guide to using Git</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Mon, 31 Aug 2020 13:39:05 +0000</pubDate>
      <link>https://forem.com/chandreshhere/beginner-s-guide-to-using-git-enk</link>
      <guid>https://forem.com/chandreshhere/beginner-s-guide-to-using-git-enk</guid>
      <description>&lt;p&gt;Want to know How to use Git in your project? &lt;br&gt;
It's really simple. &lt;/p&gt;

&lt;p&gt;Let me show you the easiest way to do that. I would suggest you to follow this tutorial on your system and by the end of this tutorial, you would have learned about all the git commands that you will be using in your new project.&lt;/p&gt;

&lt;p&gt;If you would like to watch the live examples then you can watch it here:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/OQLiJwFZ4Ag"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's start with some theory.&lt;br&gt;
&lt;a href="https://i.giphy.com/media/ZgqJGwh2tLj5C/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ZgqJGwh2tLj5C/giphy.gif" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Don't worry it won't be long and i'll try to keep it really simple.&lt;/p&gt;

&lt;p&gt;So, &lt;strong&gt;What is git?&lt;/strong&gt;&lt;br&gt;
Git is a distributed version-control system for tracking changes in source code during software development.&lt;/p&gt;

&lt;p&gt;Here is how it looks like to track changes with and without using git.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Am9g74rW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hnph6ee5kk72ghcab04w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Am9g74rW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hnph6ee5kk72ghcab04w.png" alt="Git v/s Traditional Approach"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;if you try to track changes in 1 file, after 10 changes you are gonna end up with 10 versions of your file using traditional approach.&lt;/p&gt;

&lt;p&gt;However if you are using git then you only have worry about a single file and git will track the changes for you.&lt;/p&gt;

&lt;p&gt;This is just an example for 1 file but we all know that a real project contains hundreds of such files.&lt;/p&gt;

&lt;p&gt;You now know, why we use git? but &lt;strong&gt;Why do we say it is a distributed version-control system?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using git, Each developer has a local copy with full history and changes and a copy of code can be kept on server which is where services like GitHub and bitbucket comes into picture.&lt;/p&gt;

&lt;p&gt;So anytime you make a change in your code and want to share with other developer, you just have to push your changes onto these services and the other developer can pull the changes from there.&lt;/p&gt;

&lt;p&gt;And... that's all the theory that you need to know.&lt;br&gt;
&lt;a href="https://i.giphy.com/media/4PT6v3PQKG6Yg/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/4PT6v3PQKG6Yg/giphy.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To install git on your system, Visit &lt;a href="https://git-scm.com/downloads"&gt;https://git-scm.com/downloads&lt;/a&gt; and download the software and install it on your system.&lt;/p&gt;

&lt;p&gt;Once installation is done, Open your terminal and type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git config —global user.name “Your name”
git config —global user.email “Your email”
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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

&lt;p&gt;Your name and email are displayed with every commit you make, like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UWX68foG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tl9akr09gflxgcpwj4m5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UWX68foG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tl9akr09gflxgcpwj4m5.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's start with an empty folder. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Qzjnu-cn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/627h69i82ibjriepwoyg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Qzjnu-cn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/627h69i82ibjriepwoyg.png" alt="Empty Folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a new file and write some code in it and save it as say file1.html.&lt;/p&gt;

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

&lt;p&gt;The first thing you need to do when you want start using git in your project is to initialise git using command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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

&lt;blockquote&gt;
&lt;p&gt;Note: If you already have a repository online then copy the repository url and then you can clone the repository using this command&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone your_repository_url
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;p&gt;Now add all the files to staging which will be then be added to the commit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nt"&gt;-A&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can check the changes which are to be committed using command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--36QhdZ2D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k6d0mg3pys54vi3b782d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--36QhdZ2D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k6d0mg3pys54vi3b782d.png" alt="git status"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Changes in files which are shown in green will be part of the commit that you will make.&lt;/p&gt;

&lt;p&gt;To commit your changes, type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; “your message” 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HeCt-klV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rudi1khh9v8hekgxifym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HeCt-klV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rudi1khh9v8hekgxifym.png" alt="git commit"&gt;&lt;/a&gt;&lt;br&gt;
This will create a new commit.&lt;/p&gt;

&lt;p&gt;If you check the status now then you will see that there aren’t changes done after your commit.&lt;/p&gt;

&lt;p&gt;You can check you commits history using command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git log
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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

&lt;p&gt;Each commit has a unique hash and you can see the author who made this commit and commit message here.&lt;/p&gt;

&lt;p&gt;Make some changes in your file and make another commit as done above.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7pHAdQu2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wnggt9v65kz19f33ggo6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7pHAdQu2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wnggt9v65kz19f33ggo6.png" alt="Another commit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make some more changes and create a new file say file2.html and save it.&lt;/p&gt;

&lt;p&gt;Type git status and you will see untracked files and un-staged changes in red. &lt;/p&gt;

&lt;p&gt;Now if you just want to add file1 changes to your new commit then you can type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git add file1_path
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bEpd-6HM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g41e53lsu6qjeu7pxrcd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bEpd-6HM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g41e53lsu6qjeu7pxrcd.png" alt="Commit with a new file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you check the status then it will only show you file1 in green.&lt;/p&gt;

&lt;p&gt;Now you can make a commit if you want just like we did before but what if you change your mind and want to add file2 as well in new commit. Type "git add -A" and it will add the files.&lt;/p&gt;

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

&lt;p&gt;Commit these changes like we did before.&lt;/p&gt;

&lt;p&gt;Now Let’s say you want to check the code of your project for a specific commit. How would you do that?&lt;/p&gt;

&lt;p&gt;Just copy the hash code of that commit from commits history and then use this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nb"&gt;hash&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r8H9j6dZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f9c8p9nj18c7robfy62t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r8H9j6dZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/f9c8p9nj18c7robfy62t.png" alt="git checkout hash"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And you can see the code of our project for that particular commit.&lt;/p&gt;

&lt;p&gt;Check git log again and it will show you only commits till your checkout commit.&lt;/p&gt;

&lt;p&gt;But now let’s say you want to checkout to your latest commit.&lt;br&gt;
Type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout your_branch_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nsRtfKZR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c2anjizji1j1ecu2lnns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nsRtfKZR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c2anjizji1j1ecu2lnns.png" alt="git checkout branch_name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our branch name is master(It’s created by default for you when your initialise git in a project.) in this case.&lt;/p&gt;

&lt;p&gt;Check "git log" and you will see all your commit and you are at your latest commit code in master branch.&lt;/p&gt;

&lt;p&gt;Now let’s say you want to work on a feature but don’t want to disturb your current branch. You can create a new branch for  that.&lt;br&gt;
Type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; new_branch_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pqjh9-Do--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bey6nszxsmsyzakch2zz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pqjh9-Do--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bey6nszxsmsyzakch2zz.png" alt="git checkout -b new_branch_name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we are switching to a new branch with all commit till currently checked out commit in current branch. Here “-b” flag is used to create a new branch and git checkout command to switch to new branch.&lt;/p&gt;

&lt;p&gt;Let’s make some changes again.&lt;/p&gt;

&lt;p&gt;Create a new commit and if we check our log then we can see that new commit has been done in our new branch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HieBUulZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8uuofst6v6aya1mjlb82.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HieBUulZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8uuofst6v6aya1mjlb82.png" alt="Commit in new branch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now Let’s say you are done with your feature code and want to switch to master branch.&lt;br&gt;
Type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout branch_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yCikGaBg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vszl3wvvb4m7y820cbrk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yCikGaBg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vszl3wvvb4m7y820cbrk.png" alt="git checkout branch_name"&gt;&lt;/a&gt;&lt;br&gt;
and we are back to our default branch that we were working on.&lt;/p&gt;

&lt;p&gt;To merge the changes in made in feature1 branch with your master branch. Type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git merge branch_name_from_which_you_want_to_merge_changes
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YkSR0s-N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d7qld7l3x77rpb05123x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YkSR0s-N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d7qld7l3x77rpb05123x.png" alt="git merge branch_name_from_which_you_want_to_merge_changes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this will merge all your changes from feature1 branch to your current branch that is master branch in this case.&lt;/p&gt;

&lt;p&gt;Check "git log" and we now have the feature1 changes in master branch.&lt;/p&gt;

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

&lt;p&gt;So you are done with all the changes and want to share your code with someone or may be just want to keep your changes on a service say GitHub.&lt;/p&gt;

&lt;p&gt;For that go to GitHub.com and create a new account if you  don’t already have one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Chtj3dU2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oneudcawwe0v8hv7mw8u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Chtj3dU2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oneudcawwe0v8hv7mw8u.png" alt="Create a new repository"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a new repository. &lt;/p&gt;

&lt;p&gt;Select if you want to make your repository public or private. I’m gonna select private.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0CAE4DTT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6h0p3adchlf348ria74w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0CAE4DTT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6h0p3adchlf348ria74w.png" alt="New repository"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on &lt;strong&gt;Create repository&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jnJWnihM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cao0rrfq7befjztipme6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jnJWnihM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cao0rrfq7befjztipme6.png" alt="Add remote origin"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the command here to add remote origin in your local repository.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H0fQLhPM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k7dl3c8kb2rdk9i1u1gb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H0fQLhPM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k7dl3c8kb2rdk9i1u1gb.png" alt="Add remote origin"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin branch_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0i1pJ6F0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xssw4rmvcugrdcexvv0j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0i1pJ6F0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xssw4rmvcugrdcexvv0j.png" alt="git push origin branch_name"&gt;&lt;/a&gt;&lt;br&gt;
and this will push all your code in master branch to GitHub.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you want to share the repository with a team member or a collaborator.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to settings.&lt;/p&gt;

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

&lt;p&gt;Click on “Manage Access”&lt;/p&gt;

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

&lt;p&gt;Click on &lt;strong&gt;“Invite a collaborator”&lt;/strong&gt;. Type in their GitHub username or email if and they will receive an invite from you.&lt;/p&gt;

&lt;p&gt;Once they accept your invite you can see them in your collaborators list.&lt;/p&gt;

&lt;p&gt;Now let’s say your team member accepts your invite, and make a change into it.&lt;/p&gt;

&lt;p&gt;Most likely your team member will first clone the repository on his or her local machine and then push the code on GitHub after making a change.&lt;/p&gt;

&lt;p&gt;So how will you take the change from GitHub to your local.&lt;/p&gt;

&lt;p&gt;Type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull origin branch_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZNUXSI9E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a1pz0irxid7e95eqqmho.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZNUXSI9E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a1pz0irxid7e95eqqmho.png" alt="git pull origin branch_name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this will pull in the latest changes from GitHub in master branch to your local.&lt;/p&gt;

&lt;p&gt;And that's all you need to know to start using git in any project.&lt;/p&gt;

&lt;p&gt;Hope you find this helpful!&lt;/p&gt;

</description>
      <category>git</category>
      <category>tutorial</category>
      <category>github</category>
    </item>
    <item>
      <title>Setup Queue with Serverless Laravel using bref</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Mon, 10 Aug 2020 13:49:54 +0000</pubDate>
      <link>https://forem.com/chandreshhere/setup-queue-with-serverless-laravel-using-bref-1g71</link>
      <guid>https://forem.com/chandreshhere/setup-queue-with-serverless-laravel-using-bref-1g71</guid>
      <description>&lt;p&gt;This tutorial assumes you already have a Serverless Laravel setup in place, if not then you can follow this tutorial &lt;strong&gt;"&lt;a href="https://dev.to/chandreshhere/deploy-serverless-laravel-application-using-bref-cp2"&gt;Deploy Serverless Laravel&lt;/a&gt;"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see how we can setup AWS SQS with our Serverless Laravel Application.&lt;/p&gt;

&lt;p&gt;If you would like to see me doing it then you can watch it here as well.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qThgfivpmd0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let’s Start&lt;/p&gt;

&lt;p&gt;First thing we need to do is pull in this package in your laravel application using composer.&lt;br&gt;
&lt;/p&gt;

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


&lt;p&gt;If you followed the previous tutorial then you should already be having &lt;strong&gt;serverless.yml&lt;/strong&gt; file in your Laravel application directory. Make sure it looks something like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;service: laravel-starter-serverless

provider:
    name: aws
    region: ap-south-1
    runtime: provided

plugins:
    - ./vendor/bref/bref

package:
  exclude:
    - node_modules/&lt;span class="k"&gt;**&lt;/span&gt;
    - public/storage
    - resources/assets/&lt;span class="k"&gt;**&lt;/span&gt;
    - storage/&lt;span class="k"&gt;**&lt;/span&gt;
    - tests/&lt;span class="k"&gt;**&lt;/span&gt;

functions:
    website:
        handler: public/index.php
        &lt;span class="nb"&gt;timeout&lt;/span&gt;: 28 &lt;span class="c"&gt;# in seconds (API Gateway has a timeout of 29 seconds)&lt;/span&gt;
        layers:
            - &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;bref&lt;/span&gt;:layer.php-73-fpm&lt;span class="k"&gt;}&lt;/span&gt;
        events:
            -   http: &lt;span class="s1"&gt;'ANY /'&lt;/span&gt;
            -   http: &lt;span class="s1"&gt;'ANY /{proxy+}'&lt;/span&gt;
    artisan:
        handler: artisan
        &lt;span class="nb"&gt;timeout&lt;/span&gt;: 120 &lt;span class="c"&gt;# in seconds&lt;/span&gt;
        layers:
            - &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;bref&lt;/span&gt;:layer.php-73&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="c"&gt;# PHP&lt;/span&gt;
            - &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;bref&lt;/span&gt;:layer.console&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="c"&gt;# The "console" layer&lt;/span&gt;
    worker:
        handler: worker.php
        layers:
          - &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;bref&lt;/span&gt;:layer.php-73&lt;span class="k"&gt;}&lt;/span&gt;
        events:
          &lt;span class="c"&gt;# Declares that our worker is triggered by jobs in SQS&lt;/span&gt;
            - sqs:
                arn: &lt;span class="o"&gt;!&lt;/span&gt;GetAtt AlertQueue.Arn
                &lt;span class="c"&gt;# If you create the queue manually, the line above could be:&lt;/span&gt;
                &lt;span class="c"&gt;# arn: 'arn:aws:sqs:us-east-1:1234567890:my_sqs_queue'&lt;/span&gt;
                &lt;span class="c"&gt;# Only 1 item at a time to simplify error handling&lt;/span&gt;
                batchSize: 1

resources:
  Resources:
    &lt;span class="c"&gt;# The SQS queue&lt;/span&gt;
    AlertQueue:
      Type: AWS::SQS::Queue
      Properties:
        RedrivePolicy:
          maxReceiveCount: 3 &lt;span class="c"&gt;# jobs will be retried up to 3 times&lt;/span&gt;
          &lt;span class="c"&gt;# Failed jobs (after the retries) will be moved to the other queue for storage&lt;/span&gt;
          deadLetterTargetArn: &lt;span class="o"&gt;!&lt;/span&gt;GetAtt DeadLetterQueue.Arn

    &lt;span class="c"&gt;# Failed jobs will go into that SQS queue to be stored, until a developer looks at these errors&lt;/span&gt;
    DeadLetterQueue:
      Type: AWS::SQS::Queue
      Properties:
        MessageRetentionPeriod: 1209600 &lt;span class="c"&gt;# maximum retention: 14 days&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Here we are creating a new lambda function which will act as a worker for our queue and will be invoked by a new job event from SQS.&lt;/p&gt;

&lt;p&gt;We are also creating two queues in SQS, first one will act as a queue for processing jobs and second will be used for failed jobs.&lt;/p&gt;

&lt;p&gt;Now, Create a new file &lt;strong&gt;worker.php&lt;/strong&gt; inside application directory which will handle SQS event in AWS lambda.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Bref\LaravelBridge\Queue\LaravelSqsHandler&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Illuminate\Foundation\Application&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/vendor/autoload.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="cd"&gt;/** @var Application $app */&lt;/span&gt;
&lt;span class="nv"&gt;$app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/bootstrap/app.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$kernel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$app&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Illuminate\Contracts\Console\Kernel&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$kernel&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$app&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;makeWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;LaravelSqsHandler&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'connection'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'sqs'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// this is the Laravel Queue connection&lt;/span&gt;
    &lt;span class="s1"&gt;'queue'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'SQS_QUEUE'&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;Now we need to make a small change in &lt;strong&gt;config/queue.php&lt;/strong&gt; file to add AWS session token. This may not be an issue in the latest version of laravel.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;       &lt;span class="s1"&gt;'sqs'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="o"&gt;...&lt;/span&gt;
            &lt;span class="s1"&gt;'token'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'AWS_SESSION_TOKEN'&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;Set two environment variables in &lt;strong&gt;.env&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;QUEUE_CONNECTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sqs
&lt;span class="nv"&gt;AWS_DEFAULT_REGION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ap-south-1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now before we deploy our code we need to provide permission to AWS IAM user which you created for deploying Serverless Laravel.&lt;/p&gt;

&lt;p&gt;So login into your AWS account and go to IAM. &lt;/p&gt;

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

&lt;p&gt;Click on users link and then Select your user.&lt;/p&gt;

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

&lt;p&gt;Select the policy and Click on Edit policy&lt;/p&gt;

&lt;p&gt;Click on add additional permission.&lt;/p&gt;

&lt;p&gt;Choose SQS in service.&lt;/p&gt;

&lt;p&gt;I’m giving it full access to SQS but you can selectively give it READ and WRITE access.&lt;/p&gt;

&lt;p&gt;Select all resource in resources.&lt;/p&gt;

&lt;p&gt;Click on review policy.&lt;/p&gt;

&lt;p&gt;If you get a popup asking for deleting older version of policy  then click on delete version and save.&lt;/p&gt;

&lt;p&gt;and That’s it.&lt;/p&gt;

&lt;p&gt;Type&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;serverless deploy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;and this will take care of setting up your queue and lambda function.&lt;/p&gt;

&lt;p&gt;If you get internal server error then try running:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan config:cache
&lt;span class="c"&gt;#to build all cache files&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;And then&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan config:clear
&lt;span class="c"&gt;#to remove config cache file&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Try again and this time you should see the welcome screen. Try sending a job to queue from your laravel application and you will see that that queue jobs are being processed instantly.&lt;/p&gt;

&lt;p&gt;One thing to note here is this &lt;strong&gt;/dev/&lt;/strong&gt; prefix before every route.&lt;/p&gt;

&lt;p&gt;This is because of AWS API Gateway which works in stages. &lt;br&gt;
If you want to remove this then you will have to setup a custom domain for your application on AWS or you will need to take this into account before using any route.&lt;/p&gt;

&lt;p&gt;If you have followed till now you should be having a working queue with your serverless laravel application.&lt;/p&gt;

&lt;p&gt;Hope you find this useful!&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/csinghdev"&gt;
        csinghdev
      &lt;/a&gt; / &lt;a href="https://github.com/csinghdev/laravel-starter-serverless"&gt;
        laravel-starter-serverless
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      This repository uses Bref(https://bref.sh) to create a serverless application which can be deployed on AWS Lambda. The application provides everything you need to get started with Laravel APIs development.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
About Laravel-Starter&lt;/h1&gt;
&lt;p&gt;This Starter Application acts as starting point for application
development. A lot of things which needs to be taken care of during REST API Development are already present here.&lt;/p&gt;
&lt;h2&gt;
How to deploy Serverless Laravel Application on AWS Lambda using bref?&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=rWExnXzUBqc" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/8cdf45adc9d857b05709b8a184095332636cef39/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f725745786e587a554271632f302e6a7067" alt="Deploy Serverless Laravel Application"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Following are the list of things taken care of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;JWT pre-installed&lt;/li&gt;
&lt;li&gt;Authentication APIs are ready to use&lt;/li&gt;
&lt;li&gt;Consistent Response in all APIs and Exception Handling&lt;/li&gt;
&lt;li&gt;Registration API&lt;/li&gt;
&lt;li&gt;Email Verification APIs&lt;/li&gt;
&lt;li&gt;Forgot Password APIs&lt;/li&gt;
&lt;li&gt;API Logging&lt;/li&gt;
&lt;li&gt;Backup automation and management&lt;/li&gt;
&lt;li&gt;Laravel Telescope for debugging in local environment&lt;/li&gt;
&lt;li&gt;TDD (Test Driven Development) setup using phpunit&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
Want to do it yourself?&lt;/h2&gt;
&lt;p&gt;Here are the video tutorials you can follow to do it by yourself.&lt;/p&gt;
&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.youtube.com/watch?v=MB2Dv1hqwJE" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/98537a6182e082403e9ca6478d3fef296c3f4998/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f4d42324476316871774a452f302e6a7067"&gt;&lt;/a&gt; Create a new Laravel Project&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.youtube.com/watch?v=40g0vEXOFrU" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/1d5813cdd6eeab371bc1c008121f9e47a815fe72/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f343067307645584f4672552f302e6a7067"&gt;&lt;/a&gt; JWT installation and Setup&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.youtube.com/watch?v=CKqRX9CBljU" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/f36ed79372b177ed58362bae351261fdfdd1295e/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f434b7152583943426c6a552f302e6a7067"&gt;&lt;/a&gt; Auth APIs using JWT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.youtube.com/watch?v=qNhD7DhSGzQ" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/1aa293efaac8e98d4fa2b547be832d73a5efd829/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f714e684437446853477a512f302e6a7067"&gt;&lt;/a&gt; Consistent Response in REST APIs - Part I&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.youtube.com/watch?v=4BT4NtpZDLU" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/2b4ff375eedc76aef1ffebbedf49a11f180c7922/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f344254344e74705a444c552f302e6a7067"&gt;&lt;/a&gt; Consistent Response in REST APIs - Part II&lt;/td&gt;
&lt;td&gt;
&lt;a alt="Consistent Response in REST APIs - Part II (Exception Handling)" href="https://www.youtube.com/watch?v=LChQQtdfSdY" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/c1b775e490178d62e8f34b89432544cbead3a3d5/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f4c436851517464665364592f302e6a7067"&gt;&lt;/a&gt; Registration API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.youtube.com/watch?v=xIdFl155YvA" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/23b4e79a5c33c1dac6f9b07f782d7c09280d5bff/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f784964466c3135355976412f302e6a7067"&gt;&lt;/a&gt; Email Verification APIs&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.youtube.com/watch?v=0FCkS-gqA_c" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/58642eab67fbee9d9b5e004468aa1deb549bd495/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f3046436b532d6771415f632f302e6a7067"&gt;&lt;/a&gt; Forgot Password APIs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;…&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/csinghdev/laravel-starter-serverless"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



</description>
      <category>serverless</category>
      <category>laravel</category>
      <category>queue</category>
      <category>sqs</category>
    </item>
    <item>
      <title>Deploy Serverless Laravel application using bref </title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Mon, 27 Jul 2020 09:04:03 +0000</pubDate>
      <link>https://forem.com/chandreshhere/deploy-serverless-laravel-application-using-bref-cp2</link>
      <guid>https://forem.com/chandreshhere/deploy-serverless-laravel-application-using-bref-cp2</guid>
      <description>&lt;p&gt;Let me show you a way to deploy your Laravel application on AWS Lambda for free! using bref.&lt;/p&gt;

&lt;p&gt;Why not Laravel Vapor?&lt;br&gt;
Laravel Vapor is great and if you can spend a little money then I would highly recommend that. It provides you with a nice dashboard for managing all you serverless applications and because it's built by Taylor Otwell (Creator of Laravel), So the integration and the support provided is great.&lt;/p&gt;

&lt;p&gt;But if you are just starting out with serverless and want to test few Laravel applications then this tutorial is for you.&lt;/p&gt;

&lt;p&gt;If you would like to watch me doing this then you can also watch this tutorial:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/rWExnXzUBqc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you are not familiar with concept of &lt;strong&gt;serverless&lt;/strong&gt; then it’s just an approach to &lt;strong&gt;running application without managing, configuring and provisioning servers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You won’t have to worry about scaling it even at times of peak load.&lt;br&gt;
You won’t have to pay a fixed price. &lt;br&gt;
You will only pay for the actual use which is calculated in terms of execution time and no. of executions.&lt;/p&gt;

&lt;p&gt;Sounds nice! &lt;br&gt;
Let's see how this can be done?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First requirement is to have an AWS account.&lt;/strong&gt; If you don’t have one, you can easily create one and with free tier plan you can get started for free.&lt;/p&gt;

&lt;p&gt;Once you have have it, &lt;strong&gt;Install serverless framework as global dependency using npm&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; serverless
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next we need AWS access keys. &lt;/p&gt;

&lt;p&gt;To create them go to &lt;strong&gt;IAM management console&lt;/strong&gt; of your AWS account and create a new user with programatic access. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzz5okludoavzzm5lakva.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%2Fi%2Fzz5okludoavzzm5lakva.png" alt="IAM management console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to attach a new policy for this user to provide selective access to AWS services.&lt;/p&gt;

&lt;p&gt;Click on &lt;strong&gt;"Select existing policies directly"&lt;/strong&gt; and then click on "Create policy" button.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fsmwugzqolqhk9bmmf1e8.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%2Fi%2Fsmwugzqolqhk9bmmf1e8.png" alt="Select existing policies directly"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select JSON tab.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnf87af8cohhfrw32x41f.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%2Fi%2Fnf87af8cohhfrw32x41f.png" alt="JSON"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy and paste the json below and Click on &lt;strong&gt;Review Policy&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Give it a name and Click on &lt;strong&gt;create policy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Go back to your create user page, Refresh the list, Search for your policy. Select policy and click on Next&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1uyuuzlvyynsrcytybkf.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%2Fi%2F1uyuuzlvyynsrcytybkf.png" alt="create user page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click next and finally click on &lt;strong&gt;Create User&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdq1r3vhpdk49cyv8gqtr.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%2Fi%2Fdq1r3vhpdk49cyv8gqtr.png" alt="Create User"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the &lt;strong&gt;access key id&lt;/strong&gt; and &lt;strong&gt;secret access key&lt;/strong&gt; and Setup AWS Keys using this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;serverless config credentials &lt;span class="nt"&gt;--provider&lt;/span&gt; aws &lt;span class="nt"&gt;--key&lt;/span&gt; &amp;lt;key&amp;gt; &lt;span class="nt"&gt;--secret&lt;/span&gt; &amp;lt;secret&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Your serverless framework setup is done here.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To &lt;strong&gt;integrate bref&lt;/strong&gt; in your existing laravel project.&lt;/p&gt;

&lt;p&gt;First pull in bref package using composer.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Create a new file &lt;strong&gt;serverless.yml&lt;/strong&gt; inside your project directory using this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan vendor:publish &lt;span class="nt"&gt;--tag&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;serverless-config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can edit &lt;strong&gt;serverless.yml&lt;/strong&gt; as per your requirement. &lt;/p&gt;

&lt;p&gt;Next we need to change the location of compiled view and a few other things like changing session driver to cookie and log channel to standard error in environment (.env) file.&lt;/p&gt;

&lt;p&gt;Open &lt;strong&gt;.env&lt;/strong&gt; file and add following:&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="nv"&gt;CACHE_DRIVER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;array
&lt;span class="nv"&gt;VIEW_COMPILED_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/tmp/storage/framework/views
&lt;span class="nv"&gt;SESSION_DRIVER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;array
&lt;span class="nv"&gt;LOG_CHANNEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;stderr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another issues that I faced was with caching and changing cache driver to array solved that for me. So if you get errors related to caching then you can try changing 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="nv"&gt;CACHE_DRIVER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;array
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that you can not use localhost for your mysql database here, So you have deploy it on another server and add the credentials here, Or you can even use AWS RDS service.&lt;/p&gt;

&lt;p&gt;Next we need to make changes in app service provider so that if compiled view directory is not present then it should recreate it automatically.&lt;/p&gt;

&lt;p&gt;So copy and paste below section in boot method of &lt;strong&gt;app/Providers/AppServiceProvider.php&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;boot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//&lt;/span&gt;
        &lt;span class="c1"&gt;// Make sure the directory for compiled views exist&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nb"&gt;is_dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'view.compiled'&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nb"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'view.compiled'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mo"&gt;0755&lt;/span&gt;&lt;span class="p"&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now since laravel caching breaks in AWS lambda because of different file paths, However it also breaks without package’s and service cache, So to build all cache files run&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;And to remove config cache file run&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;And That’s it&lt;/p&gt;

&lt;p&gt;To deploy it on AWS Lambda we just need to run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;serverless deploy 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and it will take care of everything else.&lt;/p&gt;

&lt;p&gt;Finally you will see your application url, copy it and try it in your browser.&lt;/p&gt;

&lt;p&gt;And it should works.&lt;/p&gt;

&lt;p&gt;That's it!&lt;/p&gt;

&lt;p&gt;Hope you find this helpful!&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>laravel</category>
      <category>bref</category>
      <category>lambda</category>
    </item>
    <item>
      <title>Automate testing for your Laravel Application using Travis-CI</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Tue, 14 Jul 2020 09:01:39 +0000</pubDate>
      <link>https://forem.com/chandreshhere/automate-testing-for-your-laravel-application-using-travis-ci-4jk4</link>
      <guid>https://forem.com/chandreshhere/automate-testing-for-your-laravel-application-using-travis-ci-4jk4</guid>
      <description>&lt;p&gt;Automate testing for you Laravel application using Travis CI. As an example I will be using a repository containing test case for an API &lt;a href="https://github.com/csinghdev/laravel-examples"&gt;https://github.com/csinghdev/laravel-examples&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you would like to watch me doing it then you can watch the  tutorial here:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Xl1HMwaD3Mg"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;p&gt;Let’s start.&lt;/p&gt;

&lt;p&gt;First thing we need to do is create an account on Travis-CI.&lt;/p&gt;

&lt;p&gt;If your application is open source then you can use &lt;br&gt;
&lt;a href="https://travis-ci.org"&gt;https://travis-ci.org&lt;/a&gt; which is completely free for Open Source Projects. &lt;/p&gt;

&lt;p&gt;For private repositories you can use &lt;a href="https://travis-ci.com"&gt;https://travis-ci.com&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In this example I will be using &lt;a href="https://travis-ci.org"&gt;https://travis-ci.org&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Create a new account on Travis-CI. It will ask you for access to your GitHub repository for first time.&lt;/p&gt;

&lt;p&gt;We have to follow these two steps here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Activate the repository for which we want to automate testing.&lt;/li&gt;
&lt;li&gt;Create a new configuration file &lt;strong&gt;.travis.yml&lt;/strong&gt; inside our repository for Travis-CI.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To activate repository, go to settings and then click on the toggle for that repository.&lt;/p&gt;

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

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

&lt;p&gt;Create a new file &lt;strong&gt;.travis.yml&lt;/strong&gt; Inside your project repository folder&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;That’s it, Add this file to git, commit your code and push it into the repository.&lt;/p&gt;

&lt;p&gt;As soon as we do that, after few seconds, our test cases starts running here for both versions of php.&lt;/p&gt;

&lt;p&gt;And after some time as we can see all test cases are done.&lt;/p&gt;

&lt;p&gt;You can find the entire code here:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/csinghdev"&gt;
        csinghdev
      &lt;/a&gt; / &lt;a href="https://github.com/csinghdev/laravel-examples"&gt;
        laravel-examples
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Laravel Examples. Built on top of https://github.com/csinghdev/laravel-starter
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
About Laravel-Examples&lt;/h1&gt;
&lt;p&gt;This application contains examples with screencasts explaining them. It is built on top of &lt;a href="https://github.com/csinghdev/laravel-starter"&gt;Laravel Starter Application&lt;/a&gt; but you can follow them for any Laravel App.&lt;/p&gt;
&lt;p&gt;Examples included:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create Custom Artisan Command&lt;/li&gt;
&lt;li&gt;Integration with Travis-CI&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
Want to do it yourself?&lt;/h2&gt;
&lt;p&gt;Here is the list of video tutorials you can follow to do it by yourself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Integration with Travis-CI&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
&lt;a href="https://www.youtube.com/watch?v=Xl1HMwaD3Mg" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/c4a0b30be23c1e46f53baad4b46e55d77d57f4e8/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f586c31484d776144334d672f302e6a7067" alt="Integration with Travis-CI"&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Create Custom Artisan Command&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
&lt;a href="https://www.youtube.com/watch?v=Ik927SLPTi0" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/492969439b7b2fc10ee4d8d15a0cfac34428be7c/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f496b393237534c505469302f302e6a7067" alt="Create Custom Artisan Command"&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;h2&gt;
Doing it on MacOS?&lt;/h2&gt;
&lt;p&gt;Here is a simple video to setup Laravel application environment on MacOS using &lt;a href="https://laravel.com/docs/7.x/valet#introduction" rel="nofollow"&gt;Valet&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=qN-QmeMm1vE" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/a30366f9c733682d9739fd2ed13e1d0926c85620/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f714e2d516d654d6d3176452f302e6a7067" alt="Install Valet on Mac"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
About Laravel&lt;/h2&gt;
&lt;p&gt;Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://laravel.com/docs/routing" rel="nofollow"&gt;Simple, fast routing engine&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://laravel.com/docs/container" rel="nofollow"&gt;Powerful dependency injection container&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Multiple back-ends for &lt;a href="https://laravel.com/docs/session" rel="nofollow"&gt;session&lt;/a&gt; and &lt;a href="https://laravel.com/docs/cache" rel="nofollow"&gt;cache&lt;/a&gt; storage.&lt;/li&gt;
&lt;li&gt;Expressive, intuitive &lt;a href="https://laravel.com/docs/eloquent" rel="nofollow"&gt;database ORM&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Database…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/csinghdev/laravel-examples"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Hope you find this useful!&lt;/p&gt;

</description>
      <category>travisci</category>
      <category>laravel</category>
      <category>github</category>
      <category>testing</category>
    </item>
    <item>
      <title>TDD in Laravel using phpunit for REST Api Development</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Tue, 07 Jul 2020 13:43:00 +0000</pubDate>
      <link>https://forem.com/chandreshhere/tdd-in-laravel-using-phpunit-for-rest-api-development-bdd</link>
      <guid>https://forem.com/chandreshhere/tdd-in-laravel-using-phpunit-for-rest-api-development-bdd</guid>
      <description>&lt;p&gt;Get started with TDD in Laravel using phpunit for REST Api Development. As an example, I will be creating an api using TDD approach to allow user to update his profile.&lt;/p&gt;

&lt;p&gt;You can also watch the entire example here:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/G-OV9Eqsouk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The idea behind TDD approach is to first make the test case before writing the actual code. So writing api code becomes easy once you have already figured out all the thing you will be doing in api while writing the test case.&lt;br&gt;
Once you have a test case in place then after each change in API you can validate if your api is working as expected by running the test case.&lt;/p&gt;

&lt;p&gt;If you look into &lt;strong&gt;phpunit.xml&lt;/strong&gt;. You will see environment variables defined like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="nt"&gt;&amp;lt;php&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;server&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"APP_ENV"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"testing"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;server&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"BCRYPT_ROUNDS"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"4"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;server&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"CACHE_DRIVER"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"array"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;server&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"DB_CONNECTION"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"sqlite"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;server&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"DB_DATABASE"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;":memory:"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;server&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"MAIL_MAILER"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"array"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;server&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"QUEUE_CONNECTION"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"sync"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;server&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"SESSION_DRIVER"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"array"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/php&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These environment variable are used while running test cases. Laravel will automatically set the environment variables defined in this file.&lt;/p&gt;

&lt;p&gt;One thing to note here is that We are using in memory database of sqlite. The advantage of using memory database is that it is created automatically in memory when you run your tests and are automatically deleted after your test cases are completed. &lt;/p&gt;

&lt;p&gt;It will not affect your actual database in use.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l2R024uE283zkmdfW/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l2R024uE283zkmdfW/giphy.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can configure these  environment variables as per your requirement.&lt;/p&gt;

&lt;p&gt;Open TestCase file. We will have to make some changes here to migrate and seed database before test case. For this override &lt;strong&gt;setUp&lt;/strong&gt; function like this.&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Tests&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Illuminate\Foundation\Testing\TestCase&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;BaseTestCase&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Illuminate\Foundation\Testing\WithFaker&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestCase&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;BaseTestCase&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;CreatesApplication&lt;/span&gt;&lt;span class="err"&gt;, WithFaker&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setUp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;parent&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;setUp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;artisan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'migrate'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;artisan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'db:seed'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;withoutExceptionHandling&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//To get the actual Exception whenever it occurs instead of Laravel handing the exception.&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;Let's try to create a new test using command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:test UserTest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Open &lt;strong&gt;tests/Feature/UsersTest.php&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Write your first test case like this:&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Tests\Feature&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;App\User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Tests\TestCase&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;JWTAuth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UsersTest&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;TestCase&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/** @test */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;a_user_can_edit_his_profile&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;first&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="nv"&gt;$token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JWTAuth&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;fromUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$attributes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;patchJson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'api/user/profile'&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="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'authorization'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"bearer &lt;/span&gt;&lt;span class="nv"&gt;$token&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;assertStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;assertDatabaseHas&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getTable&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nb"&gt;array_merge&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="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;
        &lt;span class="p"&gt;]));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here i'm using JWT but you can change it as per the package you are using to generate auth token.&lt;/p&gt;

&lt;p&gt;I'm using &lt;strong&gt;assertDatabaseHas&lt;/strong&gt; function and passing table name and the data which should be present to check if the profile is updated in database.&lt;/p&gt;

&lt;p&gt;Now, if we try to run it will fail because we haven’t created the api route yet.&lt;br&gt;
&lt;a href="https://i.giphy.com/media/1yjLtcHe5XVGHlA6Kf/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1yjLtcHe5XVGHlA6Kf/giphy.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s do that in api.php&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user/profile'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'UserController@updateProfile'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create a new controller using command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:controller UserController
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Write &lt;strong&gt;updateProfile&lt;/strong&gt; function in &lt;strong&gt;UserController&lt;/strong&gt; to allow user to edit his profile like this:&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Http\Controllers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Illuminate\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserController&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Controller&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth:api'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;updateProfile&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$attributes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|string'&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="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;update&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;"msg"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Profile successfully updated"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Try running your test case again and your test case should pass this time.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_uga2pte--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7duxa5tx036htx3wtuct.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_uga2pte--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7duxa5tx036htx3wtuct.png" alt="Test Case Passed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it!&lt;/p&gt;

&lt;p&gt;Hope you find this useful!&lt;/p&gt;

</description>
      <category>tdd</category>
      <category>phpunit</category>
      <category>api</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Laravel 7 - Forgot Password APIs using inbuilt Laravel methods</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Tue, 23 Jun 2020 08:32:54 +0000</pubDate>
      <link>https://forem.com/chandreshhere/laravel-7-forgot-password-apis-using-inbuilt-laravel-methods-4ij0</link>
      <guid>https://forem.com/chandreshhere/laravel-7-forgot-password-apis-using-inbuilt-laravel-methods-4ij0</guid>
      <description>&lt;p&gt;Want to build forgot password APIs really fast?&lt;/p&gt;

&lt;p&gt;Let me show you how to use the inbuilt Laravel methods and notification template to build forgot password APIs.&lt;/p&gt;

&lt;p&gt;If you would like to watch the in depth tutorial then you watch the tutorial here, where I explain each and everything used in code:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/0FCkS-gqA_c"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let’s Start!&lt;/p&gt;

&lt;p&gt;Create a new controller using command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:controller ForgotPasswordController
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open it and write a new function &lt;strong&gt;forgot&lt;/strong&gt; just like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;forgot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$credentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|email'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

        &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;sendResetLink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$credentials&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;"msg"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Reset password link sent on your email id.'&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;Don't forget to add &lt;strong&gt;use Illuminate\Support\Facades\Password;&lt;/strong&gt; at the top.&lt;/p&gt;

&lt;p&gt;Register route in api.php file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'password/email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'ForgotPasswordController@forgot'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, &lt;strong&gt;sendResetLink&lt;/strong&gt; function will send a reset password link with email and token in url. To make it use our route link. Create a route with route name &lt;strong&gt;'password.reset'&lt;/strong&gt;. You can either return a view directly from here or you can even redirect it to a frontend page url with parameters.&lt;/p&gt;

&lt;p&gt;As an example, here is a very basic form at resources/views/auth/reset_password.blade.php file which you can use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"{{ str_replace('_', '-', app()-&amp;gt;getLocale()) }}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Laravel Starter&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;

    &lt;span class="c"&gt;&amp;lt;!-- Fonts --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css?family=Nunito:200,600"&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="c"&gt;&amp;lt;!-- Styles --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#f1f1f1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#636b6f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Nunito'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nc"&gt;.full-height&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nc"&gt;.flex-center&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nc"&gt;.position-ref&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="n"&gt;lightgray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nc"&gt;.form-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="n"&gt;lightgray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10pt&lt;/span&gt; &lt;span class="m"&gt;14pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;14pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20pt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;lightgray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex-center position-ref full-height"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-container"&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"api/password/reset"&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;"POST"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Forgot Password?&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter email"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"{{request()-&amp;gt;get('email')}}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter new password"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"password_confirmation"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Confirm new password"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;hidden&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"token"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"token"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"{{request()-&amp;gt;get('token')}}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Register the route in &lt;strong&gt;routes/web.php&lt;/strong&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'forgot_password'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'auth.reset_password'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'password.reset'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, Let's write the function which will finally reset the password. For that create a new &lt;strong&gt;reset&lt;/strong&gt; function inside ForgotPasswordController.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$credentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
            &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'token'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|string'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'password'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|string|confirmed'&lt;/span&gt;
        &lt;span class="p"&gt;]);&lt;/span&gt;

        &lt;span class="nv"&gt;$reset_password_status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$credentials&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&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="nv"&gt;$reset_password_status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;INVALID_TOKEN&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="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;"msg"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Invalid token provided"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;400&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="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;"msg"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Password has been successfully changed"&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;Register the route inside api.php.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'password/reset'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'ForgotPasswordController@reset'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it!&lt;/p&gt;

&lt;p&gt;You can find the entire code here at &lt;a href="https://github.com/csinghdev/laravel-starter"&gt;https://github.com/csinghdev/laravel-starter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>forgot</category>
      <category>password</category>
      <category>api</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Create Custom Artisan Command in Laravel</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Sun, 14 Jun 2020 04:58:06 +0000</pubDate>
      <link>https://forem.com/chandreshhere/create-custom-artisan-command-in-laravel-1ocb</link>
      <guid>https://forem.com/chandreshhere/create-custom-artisan-command-in-laravel-1ocb</guid>
      <description>&lt;p&gt;Artisan is a frequently used command-line interface that comes with Laravel which provides a set of commands that are helpful while building your application.&lt;/p&gt;

&lt;p&gt;Let’s say you want a command to automatically email getting started guide link to users 1 day after registration.&lt;/p&gt;

&lt;p&gt;If you would like to watch me doing this then here is the tutorial.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Ik927SLPTi0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's Start!&lt;/p&gt;

&lt;p&gt;Create a new command using command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:command SendDocLinkToUsers
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Open &lt;strong&gt;app/Console/Commands/SendDocLinkToUsers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Set name and signature of your command and write a small description about your command. &lt;/p&gt;

&lt;p&gt;Inside handle function you can write your logic. It should look something like this:&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Console\Commands&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;App\Notifications\SendDocLinkNotification&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;App\User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;Illuminate\Console\Command&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SendDocLinkToUsers&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Command&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/**
     * The name and signature of the console command.
     *
     * @var string
     */&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$signature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'users:send_doc_link'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="cd"&gt;/**
     * The console command description.
     *
     * @var string
     */&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Send doc link to users 1 day after registration.'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="cd"&gt;/**
     * Create a new command instance.
     *
     * @return void
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;parent&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cd"&gt;/**
     * Execute the console command.
     *
     * @return mixed
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="na"&gt;whereNotNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email_verified_at'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;whereDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'created_at'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;subDays&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;SendDocLinkNotification&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create Email Notification that we want to send to users.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:notification SendDocLinkNotification
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Make changes in app/Notifications/SendDocLinkNotification file as per your liking.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toMail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$notifiable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;MailMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Thanks for registering. Below is the link to our get started guide.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'View Get Started Guide'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/getting_started_guide_url'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Feel free to reply to this email if you need any help in getting started.'&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;Try running the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan &lt;span class="nb"&gt;users&lt;/span&gt;:send_doc_link
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now to run it auto automatically everyday, all you need to do is set the command in Laravel scheduler. You can do this in &lt;strong&gt;app/Console/Kernel.php&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Schedule&lt;/span&gt; &lt;span class="nv"&gt;$schedule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$schedule&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'users:send_doc_link'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;daily&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'08:00'&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;Or You can even use crontab to run the command everyday.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_jHwCBs_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4plg7m384iynv213v16r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_jHwCBs_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4plg7m384iynv213v16r.png" alt="Running command using crontab"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*Note: For running Laravel scheduler you will have to set the command in either crontab or supervisor to run every minute.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SYDn8tIB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7c8zmavjjhja6b0ezzpd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SYDn8tIB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7c8zmavjjhja6b0ezzpd.png" alt="Crontab entry for running Laravel Scheduler"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can learn more about Laravel scheduler here: &lt;a href="https://laravel.com/docs/7.x/scheduling#introduction"&gt;https://laravel.com/docs/7.x/scheduling#introduction&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the entire code &lt;a href="https://github.com/csinghdev/laravel-examples"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it!&lt;/p&gt;

&lt;p&gt;Hope you find it useful.&lt;/p&gt;

</description>
      <category>artisan</category>
      <category>command</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Laravel Email Verification APIs</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Sun, 07 Jun 2020 04:37:00 +0000</pubDate>
      <link>https://forem.com/chandreshhere/laravel-email-verification-apis-246c</link>
      <guid>https://forem.com/chandreshhere/laravel-email-verification-apis-246c</guid>
      <description>&lt;p&gt;Laravel provides convenient methods for verifying email id of newly registered user but when it comes to REST APIs, Laravel doesn’t provided out of the box APIs for email verification. &lt;/p&gt;

&lt;p&gt;So today I’m gonna show how to use the inbuilt Laravel email verification methods and notification template to build email verification APIs really fast.&lt;/p&gt;

&lt;p&gt;If you would like to watch the example then you can check it out here:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/xIdFl155YvA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let’s start.&lt;/p&gt;

&lt;p&gt;In your registration api, add sendEmailVerificationNotification on user after user is created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getAttributes&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;sendEmailVerificationNotification&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to see the implementation of this function then you can find it here at &lt;em&gt;Illuminate\Auth\MustVerifyEmail&lt;/em&gt;. This function is available in User model because it extends &lt;em&gt;Authenticatable&lt;/em&gt; which uses &lt;em&gt;Illuminate\Auth\MustVerifyEmail&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You can find the notification template here at  &lt;em&gt;Illuminate\Auth\Notifications\VerifyEmail&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Define endpoints in api.php file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email/verify/{id}'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'VerificationController@verify'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'verification.verify'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Make sure to keep this as your route name&lt;/span&gt;

&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email/resend'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'VerificationController@resend'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'verification.resend'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create this VerificationController using command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan make:controller VerificationController
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open VerificationController and define verify and resend function like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&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="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasValidSignature&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="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;"msg"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Invalid/Expired url provided."&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;findOrFail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user_id&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="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasVerifiedEmail&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;markEmailAsVerified&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="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;resend&lt;/span&gt;&lt;span class="p"&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="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasVerifiedEmail&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="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;"msg"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Email already verified."&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;sendEmailVerificationNotification&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s2"&gt;"msg"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Email verification link sent on your email id"&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;Try this in postman and they should look something like this. Since i have defined some methods to keep the response consistent, So the response will be different. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verification API&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdy2n1g767dmldqdh1mgv.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%2Fi%2Fdy2n1g767dmldqdh1mgv.png" alt="Verify"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resend API&lt;/strong&gt;:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0rgrbus1mqg2erzwocqu.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%2Fi%2F0rgrbus1mqg2erzwocqu.png" alt="Resend"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to make your &lt;strong&gt;response consistent across application&lt;/strong&gt; then you can watch the tutorials below.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qNhD7DhSGzQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/4BT4NtpZDLU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can find the entire code &lt;a href="https://github.com/csinghdev/laravel-starter" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope you find it useful.&lt;/p&gt;

</description>
      <category>email</category>
      <category>verification</category>
      <category>api</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Setup Laravel Project on Server (Ubuntu 18.04)</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Sat, 30 May 2020 08:28:05 +0000</pubDate>
      <link>https://forem.com/chandreshhere/setup-laravel-project-on-server-ubuntu-18-04-316p</link>
      <guid>https://forem.com/chandreshhere/setup-laravel-project-on-server-ubuntu-18-04-316p</guid>
      <description>&lt;p&gt;To setup laravel project on a Server with Ubuntu 18.04 from scratch, you need to do following:&lt;/p&gt;

&lt;p&gt;You can watch this example here as well:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/-H4QQmQBzKw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's Start!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;em&gt;PHP&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo apt-get update&lt;br&gt;
sudo apt-get install php&lt;br&gt;
sudo apt-get install php7.2-mbstring php7.2-mysql php7.2-xml php7.2-curl php7.2-json php7.2-zip&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;em&gt;Apache&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo apt-get install apache2&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;em&gt;Git&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo apt-get install git&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;em&gt;Composer&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;curl -sS &lt;a href="https://getcomposer.org/installer"&gt;https://getcomposer.org/installer&lt;/a&gt; | php&lt;br&gt;
sudo mv composer.phar /usr/local/bin/composer&lt;br&gt;
chmod +x /usr/local/bin/composer&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Clone laravel project from your repository&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git clone &lt;a href="https://github.com/csinghdev/laravel-starter.git"&gt;https://github.com/csinghdev/laravel-starter.git&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Setup Laravel app&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cd laravel-starter&lt;br&gt;
composer install&lt;br&gt;
cp .env.example .env&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add/Edit Project Environment variables&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;nano .env&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create virtual host in apache and map subdomain to your Laravel app. You can watch it here.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/zFMCh_y0O7o"&gt;
&lt;/iframe&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;That’s it!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>laravel</category>
      <category>ubuntu</category>
      <category>php</category>
      <category>apache</category>
    </item>
    <item>
      <title>Map Subdomain with Web Application</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Thu, 21 May 2020 14:16:41 +0000</pubDate>
      <link>https://forem.com/chandreshhere/map-subdomain-with-web-application-212j</link>
      <guid>https://forem.com/chandreshhere/map-subdomain-with-web-application-212j</guid>
      <description>&lt;p&gt;For mapping subdomain with Web app we need to creating DNS entry through Domain Service Provider account for linking subdomain and server and then we need to create a virtual host configuration for telling web server to direct all requests on subdomain to our web app.&lt;/p&gt;

&lt;p&gt;If you would like to watch me doing that then you can watch it here as well.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/zFMCh_y0O7o"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's first start with creating a virtual host on apache. &lt;/p&gt;

&lt;p&gt;For that, SSH on your Server.&lt;/p&gt;

&lt;p&gt;Make sure you have root access. Switch to root user.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo su root&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to apache site configurations directory&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cd /etc/apache2/sites-available&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Create a new configuration file for your site.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;nano app.example.com.conf&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Configure virtual host like this. Make sure that the path in document root and directory should be the path of your web app directory containing index file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;VirtualHost &lt;span class="k"&gt;*&lt;/span&gt;:80&amp;gt;
        ServerAdmin admin@example.com
        ServerName  app.example.com
        ServerAlias www.app.example.com
        DocumentRoot /var/www/example_app

        ErrorLog &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APACHE_LOG_DIR&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/app.example.com-error.log
        CustomLog &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APACHE_LOG_DIR&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/app.example.com-access.log combined

        &amp;lt;Directory /var/www/example_app/&amp;gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                Require all granted
        &amp;lt;/Directory&amp;gt;
&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Save the file.&lt;/p&gt;

&lt;p&gt;Enable site configuration.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;a2ensite app.example.com.conf&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reload web server.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;service reload apache2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go to your domain service provider.&lt;/p&gt;

&lt;p&gt;Open DNS Settings page.&lt;/p&gt;

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

&lt;p&gt;Add a new A type Record with your subdomain and IP address of your server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gOFJWhmR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cwm6tiaz3cbbo2k6v5w4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gOFJWhmR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cwm6tiaz3cbbo2k6v5w4.png" alt="New A type Record"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wait for some time. Usually it gets live within few hours but depending upon your domain service provider, it may take unto 48 hours.&lt;/p&gt;

&lt;p&gt;That’s it!&lt;/p&gt;

&lt;p&gt;You can now access your web app using your subdomain.&lt;/p&gt;

</description>
      <category>subdomain</category>
      <category>server</category>
      <category>apache</category>
      <category>virtualhost</category>
    </item>
    <item>
      <title>Laravel - Automate Database Backup</title>
      <dc:creator>Chandresh Singh</dc:creator>
      <pubDate>Thu, 14 May 2020 15:08:42 +0000</pubDate>
      <link>https://forem.com/chandreshhere/laravel-automate-database-backup-3cc</link>
      <guid>https://forem.com/chandreshhere/laravel-automate-database-backup-3cc</guid>
      <description>&lt;p&gt;Backup your database and automate the process using this simple method. &lt;/p&gt;

&lt;p&gt;If you want to watch me doing it then below is the tutorial video for the same.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/11ECvHYMfRY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let’s Start!&lt;/p&gt;

&lt;p&gt;Pull in the package “laravel-backup” using composer.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer require spatie/laravel-backup&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Publish config file using this command.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Open backup.php inside config folder.&lt;/p&gt;

&lt;p&gt;There are a bunch of configuration settings here:&lt;/p&gt;

&lt;p&gt;In the source, Write your file path or directory that you want to include or exclude from backup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F99ff66n3zmodd6t05x0y.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%2Fi%2F99ff66n3zmodd6t05x0y.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Write the database connection name which you want to backup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftdvf8yn1qkr8wqvbygit.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%2Fi%2Ftdvf8yn1qkr8wqvbygit.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Within destination, Write disk name on which you want to store backups. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh9lk5iavkmsa6c9uc01k.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%2Fi%2Fh9lk5iavkmsa6c9uc01k.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to store them in AWS S3 then you can define your disk in filesystems.php. &lt;/p&gt;

&lt;p&gt;For using S3, pull in the package "league/flysystem-aws-s3-v3"&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;composer require "league/flysystem-aws-s3-v3"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Write your S3 access credentials in .env file.&lt;/p&gt;

&lt;p&gt;Select the notifications that you want to receive and Write your email id on which you want to receive your notification.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flg6i6rxkbjh83deqoohl.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%2Fi%2Flg6i6rxkbjh83deqoohl.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can even get these notification on slack as well. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fclk622vavi3yy7huwwld.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%2Fi%2Fclk622vavi3yy7huwwld.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Configure email service if you haven’t from mail.php and write mail service credentials in .env file.&lt;/p&gt;

&lt;p&gt;Set the no of days you want your backups to kept and deleted automatically after a certain time period.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffp1cmkvu1chw6b5hgakx.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%2Fi%2Ffp1cmkvu1chw6b5hgakx.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Schedule these commands using Laravel Scheduler. For that Open app/Console/Kernel.php and write these inside schedule function.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$schedule-&amp;gt;command('backup:clean')-&amp;gt;daily()-&amp;gt;at('01:00');&lt;br&gt;
$schedule-&amp;gt;command('backup:run')-&amp;gt;daily()-&amp;gt;at('02:00');&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Set your Laravel Scheduler to run every minute using either crontab or supervisor. &lt;/p&gt;

&lt;p&gt;For crontab, it should look 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;* * * * * cd /path-to-your-project &amp;amp;&amp;amp; php artisan schedule:run &amp;gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhopjplyq1p74b6w18buy.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%2Fi%2Fhopjplyq1p74b6w18buy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's It!&lt;/p&gt;

&lt;p&gt;All your backups now will be stored and you will be notified on email or slack and old backups will also be deleted automatically as configured by you in backup.php.&lt;/p&gt;

</description>
      <category>backup</category>
      <category>laravelbackup</category>
      <category>backupmanagement</category>
      <category>automaticbackups</category>
    </item>
  </channel>
</rss>
