<?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: Saquib Rizwan</title>
    <description>The latest articles on Forem by Saquib Rizwan (@rizwan_saquib).</description>
    <link>https://forem.com/rizwan_saquib</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%2F15675%2F57337bfd-76a3-436a-9372-102c36839e4f.jpg</url>
      <title>Forem: Saquib Rizwan</title>
      <link>https://forem.com/rizwan_saquib</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rizwan_saquib"/>
    <language>en</language>
    <item>
      <title>Create &amp; Manage User Registration System with Laravel Queues &amp; Supervisor</title>
      <dc:creator>Saquib Rizwan</dc:creator>
      <pubDate>Tue, 28 Nov 2017 08:48:56 +0000</pubDate>
      <link>https://forem.com/rizwan_saquib/create--manage-user-registration-system-with-laravel-queues--supervisor-nl</link>
      <guid>https://forem.com/rizwan_saquib/create--manage-user-registration-system-with-laravel-queues--supervisor-nl</guid>
      <description>&lt;p&gt;With the recent release of Laravel 5.5 and Laravel Horizon, the framework now offer queue management. Laravel queues allow you to defer the processing of a time- consuming task (a good example is email sending) to a later time. This speeds up web request processing for your application.&lt;/p&gt;

&lt;p&gt;In this article, I will create a user registration system, which sends a verification email to the user. To demonstrate the capabilities of Laravel queues and its impact on the application speed, I will let it manage the email sending process. so that the application performs faster. &lt;/p&gt;

&lt;p&gt;For the purpose of this tutorial, I will use the Cloudways platform because it provides Supervised queue manager for Laravel applications. To begin, I will launch a Cloudways server with the Laravel application installed. &lt;/p&gt;

&lt;p&gt;PS: If you need help with the signup and the server launch process, here’s a handy GIF:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--32b1rqH0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://www.cloudways.com/blog/wp-content/uploads/Laravel-Gif.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--32b1rqH0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://www.cloudways.com/blog/wp-content/uploads/Laravel-Gif.gif" alt="Createing Server"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure the .env file
&lt;/h2&gt;

&lt;p&gt;Now that you have installed the Laravel application, the next step is database configuration.&lt;/p&gt;

&lt;p&gt;I will use the Gmail to &lt;a href="http://www.cloudways.com/blog/send-email-in-laravel/"&gt;send verification emails&lt;/a&gt;. Open the &lt;strong&gt;Applications&lt;/strong&gt; tab in the Cloudways platform. In the **Application Access **details, you will see the database path and credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HTKbywlX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.cloudways.com/blog/wp-content/uploads/image2-64.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HTKbywlX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.cloudways.com/blog/wp-content/uploads/image2-64.png" alt="App Access Details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now go to the &lt;strong&gt;.env&lt;/strong&gt; file (located in the application’s public root folder) and add the credentials there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
QUEUE_DRIVER=database

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE= your.database.name                                                                                                                            

DB_USERNAME= your.database.username                                                                                                                             

DB_PASSWORD= your.database.password

MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME=Saquib.gt@xyz.com

MAIL_PASSWORD=

MAIL_ENCRYPTION=tls

MAIL_FROM_ADDRESS=Saquib.gt@xyz.com

MAIL_FROM_NAME="Saquib Rizwan”

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating Laravel Auth
&lt;/h2&gt;

&lt;p&gt;To make the user registration system, the first thing I need to do is to create a Laravel auth using:&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="n"&gt;php&lt;/span&gt; &lt;span class="n"&gt;artisan&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;auth&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Update the Users Table
&lt;/h2&gt;

&lt;p&gt;Let’s first update the existing migration file for the user. Open the user table migration file (located in the database/migrations folder) and add two new columns in it, one for email tokens, and the second to check whether the user has been verified.&lt;/p&gt;

&lt;p&gt;The following is the updated schema for the User table:&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;Schema&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="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Blueprint&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;increments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="err"&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="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;tinyInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;verified&lt;/span&gt;&lt;span class="err"&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="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email_token&lt;/span&gt;&lt;span class="err"&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="nf"&gt;nullable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;rememberToken&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;timestamps&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;h2&gt;
  
  
  Create Table for Queues
&lt;/h2&gt;

&lt;p&gt;I will now add the table for queued jobs and failed job. For that, run the following Artisan commands:&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="n"&gt;php&lt;/span&gt; &lt;span class="n"&gt;artisan&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;

&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="n"&gt;artisan&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;failed&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Migrate the Tables
&lt;/h2&gt;

&lt;p&gt;Now that I have all the required tables, I will migrate it using the following Artisan command:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yqELrN43--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4mdqqrv3njd7pf3m8gx7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yqELrN43--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/4mdqqrv3njd7pf3m8gx7.png" alt="Migrate"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the command is completed, all the tables will be generated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Mail And the View For Email Verifications
&lt;/h2&gt;

&lt;p&gt;Since I have setup SMTP to send emails, it’s time to create an email class which will return view and token to be sent with the email. Run the following Artisan command to create the email setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:mail EmailVerification

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

&lt;/div&gt;



&lt;p&gt;Once the command finishes, a new folder with the name Mail along with the **EmailVerification **class file will be created inside the app folder. I will call this file when sending email(s). &lt;/p&gt;

&lt;h2&gt;
  
  
  Update the EmailVerification Class
&lt;/h2&gt;

&lt;p&gt;This class comes with two methods. The first is the &lt;strong&gt;constructor(),&lt;/strong&gt; and the second is the &lt;strong&gt;build(),&lt;/strong&gt; which will do most of the work. It binds the view with the email.&lt;/p&gt;

&lt;p&gt;I will send a user token along with the view so that the user can be verified. For this, add a new protected variable in the class with the name &lt;strong&gt;$user&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Now, add a new &lt;strong&gt;$user&lt;/strong&gt; parameter in the constructor and pass this to the class variable &lt;strong&gt;$user&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;__construct&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="c1"&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="n"&gt;user&lt;/span&gt; &lt;span class="o"&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="nc"&gt;Next&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt; &lt;span class="n"&gt;so&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;view&lt;/span&gt; &lt;span class="n"&gt;along&lt;/span&gt; &lt;span class="n"&gt;with&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="mf"&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;build&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="err"&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="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;

&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email_token&lt;/span&gt;&lt;span class="err"&gt;’&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="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;email_token&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;h2&gt;
  
  
  Create the Email Template
&lt;/h2&gt;

&lt;p&gt;For creating the email template, create a new folder inside &lt;strong&gt;views&lt;/strong&gt; folder with name &lt;strong&gt;email,&lt;/strong&gt; and then create a new file inside this folder with the name &lt;strong&gt;email.blade.php&lt;/strong&gt;. This file will contain the following simple template:&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="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Click the Link To Verify Your Email&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

Click the following link to verify your email {{url(‘/verifyemail/’.$email_token)}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The view for the email is now complete. Next, I will create a new queue that will send the email(s) to the registered users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the SendVerficationEmail Queue Job
&lt;/h2&gt;

&lt;p&gt;Now run the following Artisan command to make a new queue job&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:job SendVerificationEmail
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the command finishes, a new folder with the name &lt;strong&gt;Jobs&lt;/strong&gt; appears inside the app folder along with the &lt;strong&gt;SendVerificationEmail&lt;/strong&gt; job class. I will now edit this file so that it could be used to send an email.&lt;/p&gt;

&lt;p&gt;First, add Mail and EmailVerification namespaces in it.&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="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Mail&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Mail\EmailVerification&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create a new protected variable, &lt;strong&gt;$user&lt;/strong&gt; (also created in the &lt;strong&gt;EmailVerification&lt;/strong&gt; class). Next, add a new parameter &lt;strong&gt;$user&lt;/strong&gt; in the &lt;strong&gt;constructor()&lt;/strong&gt; and pass its value to the class &lt;strong&gt;$user&lt;/strong&gt; variable:&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;protected&lt;/span&gt; &lt;span class="nv"&gt;$user&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;__construct&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;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&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="nc"&gt;Next&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;I&lt;/span&gt; &lt;span class="n"&gt;will&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt; &lt;span class="n"&gt;up&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="n"&gt;sending&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="n"&gt;inside&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="mf"&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;handle&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="nv"&gt;$email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EmailVerification&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="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nc"&gt;Mail&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;to&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="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;email&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;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$email&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;The &lt;strong&gt;handle **function creates an instance of email verification template that is passed to **Mail&lt;/strong&gt; for sending off the email to a user.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update the Auth Registration Process
&lt;/h2&gt;

&lt;p&gt;Before getting started, add ‘&lt;strong&gt;email_token&lt;/strong&gt;’ in &lt;strong&gt;$fillable&lt;/strong&gt; array in the &lt;strong&gt;User&lt;/strong&gt; Model.&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;protected&lt;/span&gt; &lt;span class="nv"&gt;$fillable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;

&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="n"&gt;email_token&lt;/span&gt;&lt;span class="err"&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 open &lt;strong&gt;RegisterController.php&lt;/strong&gt; file (located inside the Controller/Authfolder).&lt;/p&gt;

&lt;p&gt;First add the following namespaces:&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="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Auth\Events\Registered&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Jobs\SendVerificationEmail&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Now modify the &lt;strong&gt;create()&lt;/strong&gt; method and add the &lt;strong&gt;email_token&lt;/strong&gt; in it.&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;protected&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="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="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;

&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;

&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;

&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email_token&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;base64_encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="err"&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;For the email token, I have used the base64 encoding for the user’s email address. Next I added the following two new functions in it:&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="cd"&gt;/**

* Handle a registration request for the application.

*

* @param \Illuminate\Http\Request $request

* @return \Illuminate\Http\Response

*/&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;register&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validator&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;all&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="nf"&gt;event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Registered&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;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;all&lt;/span&gt;&lt;span class="p"&gt;())));&lt;/span&gt;

&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SendVerificationEmail&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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;verification&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cd"&gt;/**

* Handle a registration request for the application.

*

* @param $token

* @return \Illuminate\Http\Response

*/&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;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$token&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;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;email_token&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;$token&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;first&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;verified&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="k"&gt;if&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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;emailconfirm&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="err"&gt;’&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="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;What I have done is to override the **register() **parent method and added two new lines in it.&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="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SendVerificationEmail&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="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;verification&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way the email is dispatched into the queue. Instead of directly logging in the user, I will redirect him to another page, which will ask him to verify his email in order to continue. Next, I have created a new &lt;strong&gt;verify()&lt;/strong&gt; method that will verify the user and the token. &lt;/p&gt;

&lt;p&gt;I will next create the views that I called in these two methods.&lt;/p&gt;

&lt;p&gt;Create a new file in the views folder with the name &lt;strong&gt;emailconfirm.blade.php&lt;/strong&gt; and paste the following code in it.&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;extends&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;layouts&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="nf"&gt;section&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"container”&amp;gt;

&amp;lt;div class="&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"col-md-8 col-md-offset-2"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"panel panel-default”&amp;gt;

&amp;lt;div class="&lt;/span&gt;&lt;span class="n"&gt;panel&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;heading&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Registration&lt;/span&gt; &lt;span class="nc"&gt;Confirmed&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"panel-body”&amp;gt;

Your Email is successfully verified. Click here to &amp;lt;a href="&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;&lt;span class="nf"&gt;url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;login&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)}}&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;login&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;endsection&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Create another file in the views folder with the name &lt;strong&gt;verification.blade.php&lt;/strong&gt;. Paste the following code in it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;
&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="k"&gt;extends&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;layouts&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="nf"&gt;section&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"container”&amp;gt;

&amp;lt;div class="&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"col-md-8 col-md-offset-2"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"panel panel-default”&amp;gt;

&amp;lt;div class="&lt;/span&gt;&lt;span class="n"&gt;panel&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;heading&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Registration&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"panel-body”&amp;gt;

You have successfully registered. An email is sent to you for verification.

&amp;lt;/div&amp;gt;

&amp;lt;/div&amp;gt;

&amp;lt;/div&amp;gt;

&amp;lt;/div&amp;gt;

&amp;lt;/div&amp;gt;

@endsection
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point the code is complete and ready for use. Let’s give it a try.&lt;/p&gt;

&lt;p&gt;Add the following route in the &lt;strong&gt;web.php&lt;/strong&gt; file for user verification:&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="err"&gt;‘&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;verifyemail&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nc"&gt;Auth\RegisterController&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;verify&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Test the Email Verification Process
&lt;/h2&gt;

&lt;p&gt;At the command line, execute the following command to start listening for the queue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan queue:work

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

&lt;/div&gt;



&lt;p&gt;Leave the window of the command line open and open up the register page in another tab. Fill in the form and register a new user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mUJJU3_d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/lhttwsrfwrnmzw5dsonq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mUJJU3_d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/lhttwsrfwrnmzw5dsonq.png" alt="test"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you click the Register button, you will notice that the registration confirmation page opens up quickly because it is dispatched into the queue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dZyxMswD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/5hsre4cenc4l39poydq7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dZyxMswD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/5hsre4cenc4l39poydq7.png" alt="registration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now look at command line: a new job has been processed successfully.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j8S4tOUF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/26inthrcdglnpd8yx3o2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j8S4tOUF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/26inthrcdglnpd8yx3o2.png" alt="cli"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This means that an email has been sent to the user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--644XyRwn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dy1ouuexps3mfni9dr7y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--644XyRwn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/dy1ouuexps3mfni9dr7y.png" alt="cli"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When the user click the link, he/she will be verified:&lt;/p&gt;

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

&lt;p&gt;Once you close the terminal, the queue will stop working. If you want the queue to keep working, you need to use Supervised Queue Manager. &lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Supervisord
&lt;/h2&gt;

&lt;p&gt;Go to &lt;strong&gt;Server Management &amp;gt;&amp;gt; Settings &amp;amp; Packages &amp;gt;&amp;gt; Packages&lt;/strong&gt;. Click the **Install **button next to Supervisord to start the installation process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yp-Grcgk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/901qywjxwjcsugx7f0f5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yp-Grcgk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/901qywjxwjcsugx7f0f5.jpg" alt="Supervisor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before the process starts, you will be asked to install Redis on the server (if it is not already installed), as it is required for Laravel queues. Wait for the installation process to finish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c4kxVCND--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d4oe5zg3an1tpfmpkkyc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c4kxVCND--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d4oe5zg3an1tpfmpkkyc.png" alt="Supervisor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: You can check Supervisord service status from &lt;strong&gt;Manage Services&lt;/strong&gt; section. You could even restart the service if required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add A New Job
&lt;/h2&gt;

&lt;p&gt;Under &lt;strong&gt;Application Management&lt;/strong&gt;, go to &lt;strong&gt;Application Settings **and select the tab for **Supervisor Jobs&lt;/strong&gt;. Click the Add New Job button to add a job for Supervisord.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sdq2_KcD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9hi3clil3d8ommpfp035.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sdq2_KcD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/9hi3clil3d8ommpfp035.png" alt="Supervisor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---LduvkgI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7loam3we2cilzijc8fkk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---LduvkgI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/7loam3we2cilzijc8fkk.png" alt="Supervisor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Once a job has been created, Supervisord will use the platform default Artisan path which should be &lt;strong&gt;/home/master/applications/public_html/artisan&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Job Status and other options
&lt;/h2&gt;

&lt;p&gt;The job status can be checked by clicking the Jobs Status button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wIf5WJOB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/u4kf51a1vsx7e3uek559.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wIf5WJOB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/u4kf51a1vsx7e3uek559.png" alt="Supervisor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will show the status of job and other related information including uptime.&lt;/p&gt;

&lt;p&gt;If you want to restart any job, click the icon in front of it. There is also the option of removing any job by clicking the remove icon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W8seszSW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xmvu1094mfax99dseo8m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W8seszSW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/xmvu1094mfax99dseo8m.png" alt="Supervisor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will supervise your Laravel queues and keep them up and running. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, I demonstrated how you can use Laravel queues by building a user registration system. Additionally, I also showed how you can keep your process up and run with the help of a supervisor. If you need any help, just post a comment.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>laravel</category>
      <category>php</category>
    </item>
    <item>
      <title>Blackfriday, Cybermonday and ThanksGiving to Dev.to Community. </title>
      <dc:creator>Saquib Rizwan</dc:creator>
      <pubDate>Tue, 21 Nov 2017 19:23:42 +0000</pubDate>
      <link>https://forem.com/rizwan_saquib/blackfriday-cybermonday-and-thanksgiving-to-devto-community-18d</link>
      <guid>https://forem.com/rizwan_saquib/blackfriday-cybermonday-and-thanksgiving-to-devto-community-18d</guid>
      <description>&lt;p&gt;Dev.to is one of my favorite community of developers. Therefore on this year's Thanksgiving, I would like to thank you all for being such a great help at every step of development.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NTw8C4fk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://www.cloudways.com/blog/wp-content/uploads/Blog-gif.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NTw8C4fk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://www.cloudways.com/blog/wp-content/uploads/Blog-gif.gif" alt="Black friday"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the Thanksgiving week. There is the Black Friday, then the Cyber Monday, then the Small Business Saturday, and there is a Sunday in between as well, So To enhance the joy of this week I would like to share 99+ Handpicked Black Friday Deals For WordPress, Magento, Laravel, Web Hosting &amp;amp; Web Dev Tools &lt;/p&gt;

&lt;p&gt;Also We at Cloudways are Giving $150 Credit on promo code: BF150. &lt;/p&gt;

&lt;p&gt;For &lt;a href="http://www.cloudways.com/blog/wp-content/uploads/Blog-gif.gif"&gt;more details&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>offers</category>
    </item>
    <item>
      <title>Creating a Laravel Notification System</title>
      <dc:creator>Saquib Rizwan</dc:creator>
      <pubDate>Thu, 09 Nov 2017 12:08:50 +0000</pubDate>
      <link>https://forem.com/rizwan_saquib/creating-a-laravel-notification-system-6mb</link>
      <guid>https://forem.com/rizwan_saquib/creating-a-laravel-notification-system-6mb</guid>
      <description>&lt;p&gt;An important reason of the popularity of Laravel is the simple fact that provides feasible solutions to the common development issues such as authentication, contact forms,  sessions, queues, routing, and caching etc.&lt;/p&gt;

&lt;p&gt;A common project requirement in Laravel projects is notification generation. In this article, I will present the solution by creating a Laravel notification system. In this system, whenever a user visits the page, a notification will be sent to you through email. To sweeten the deal, I will also integrate Slack to setup the notification for a Slack channel. &lt;/p&gt;

&lt;p&gt;Laravel’s notification system is simple to implement because it generate notifications by setting up a single class for each notification. This class defines how to notify users about the message using a particular channel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Laravel Application
&lt;/h2&gt;

&lt;p&gt;To quickly setup a Laravel application, I am using &lt;a href="https://www.cloudways.com/en/laravel-hosting.php" rel="noopener noreferrer"&gt;Laravel Hosting&lt;/a&gt; at Cloudways. Just sign up at Cloudways and install Laravel application in just few clicks for free. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2FLaravel-Gif.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2FLaravel-Gif.gif" alt="Host Laravel" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a User Table
&lt;/h2&gt;

&lt;p&gt;After the installation, create a User table. Launch the SSH terminal and login to your server using the Master Credentials (available in the Server Management tab).. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgiotjuquk2sbcfs7nb1t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgiotjuquk2sbcfs7nb1t.png" alt="Laravel notification" width="768" height="301"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now go to the root of the application by typing the following commands:&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="n"&gt;cd&lt;/span&gt; &lt;span class="n"&gt;applications&lt;/span&gt;

&lt;span class="n"&gt;cd&lt;/span&gt; &lt;span class="n"&gt;applicationname&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;public_html&lt;/span&gt;

&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="n"&gt;artisan&lt;/span&gt; &lt;span class="n"&gt;migrate&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;User table is now created in the database. &lt;/p&gt;

&lt;p&gt;Now let's add some records into it so that the system can send notifications to that user. Go to the Database Manager and add a simple record in the table. Make sure to add a valid email id because the system will send the notification to this email address.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F034ofh79i2zs4tobr897.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F034ofh79i2zs4tobr897.png" alt="Laravel Notification" width="768" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that the user model is created let’s take a look at it. Go to &lt;strong&gt;app/User.php&lt;/strong&gt; that has the following code:&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;?php&lt;/span&gt;

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

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Notifications\Notifiable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Foundation\Auth\User&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;Authenticatable&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;User&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Authenticatable&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;

   &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Notifiable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$fillable&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="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

   &lt;span class="p"&gt;];&lt;/span&gt;

   &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$hidden&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;

       &lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'remember_token'&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;If you look closely, &lt;strong&gt;Notifiable&lt;/strong&gt; trait is been used. Whenever you want to make your model notifiable, all you have to do is import &lt;strong&gt;use Illuminate\Notifications\Notifiable;&lt;/strong&gt; trait in your model.&lt;/p&gt;

&lt;p&gt;Just note that certain notification channels expects certain information available on the notifiable. For example, the mail channel expects the model to have an "email" property so it knows which email address to send the notification.&lt;/p&gt;

&lt;h2&gt;
  
  
  Notification Via Email
&lt;/h2&gt;

&lt;p&gt;Go back to SSH, head to the root of your application and execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
php artisan make:notification Newvisit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, go to &lt;strong&gt;app/Notifications/Newvisit.php.&lt;/strong&gt; In this file you will find the following code:&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;?php&lt;/span&gt;

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

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Bus\Queueable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Notifications\Notification&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Contracts\Queue\ShouldQueue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Notifications\Messages\MailMessage&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;Newvisit&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Notification&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;

   &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Queueable&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;__construct&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="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;via&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="s1"&gt;'mail'&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;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="nc"&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="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'The introduction to the notification.'&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;action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Notification Action'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;url&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="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Thank you for using our application!'&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;toArray&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="c1"&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;Let’s understand this code. First, it has the constructor, where any relevant data will be injected.&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;via&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="s1"&gt;'mail'&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;Then, it has the via() method, which allows you to choose the notification method which will be used to send the notification to each individual instance.&lt;br&gt;
Then, it has **toMail() **method, which returns three attributes. The first one is line, which specifies the starting body of the email. Then it has action, which specifies the button name and the URL to which the button will redirect. Finally, it has line again, which specifies the closing paragraph of the email. Here is a sample output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;
       &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'The introduction to the notification.'&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;action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Notification Action'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'https://laravel.com'&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;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Thank you for using our application!'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sscmd2vz3rtv5rb836p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sscmd2vz3rtv5rb836p.png" alt="Laravel notification" width="599" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Send Notifications Via Email in Laravel
&lt;/h2&gt;

&lt;p&gt;Go to &lt;strong&gt;routes/web.php&lt;/strong&gt; and paste the following code in the 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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Notifications\Newvisit&lt;/span&gt;&lt;span class="p"&gt;;&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;'/'&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="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;App\User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;first&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;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Newvisit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"A new user has visited on your application."&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;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'welcome'&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;You would have to import notification class through &lt;strong&gt;use App\Notifications\Newvisit;&lt;/strong&gt; then in the route function, I have called the first record from the User table which I inserted by** $user = App\User::first();. &lt;strong&gt;Next, the notification is sent for which I used the **notify&lt;/strong&gt; function and send the notification in Newvisit instance in the following line of code: &lt;strong&gt;$user-&amp;gt;notify(new Newvisit("A new user has visited on your application."));&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now open &lt;strong&gt;app\Notifications\Newvisit.php&lt;/strong&gt; and add the following code in it.&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;?php&lt;/span&gt;

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

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Bus\Queueable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Notifications\Notification&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Contracts\Queue\ShouldQueue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Notifications\Messages\MailMessage&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;Newvisit&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Notification&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;

   &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Queueable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$my_notification&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;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$msg&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="n"&gt;my_notification&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$msg&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;via&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="s1"&gt;'mail'&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;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="nc"&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="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Welcome '&lt;/span&gt;&lt;span class="mf"&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="n"&gt;my_notification&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;action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Welcome to Cloudways'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'www.cloudways.com'&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;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Thank you for using our application!'&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;toArray&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="c1"&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;Next open &lt;strong&gt;.env&lt;/strong&gt; file and set the database credentials and mailer function. Check out the &lt;a href="https://www.cloudways.com/blog/send-email-in-laravel/" rel="noopener noreferrer"&gt;Laravel Email&lt;/a&gt; article for details of this step. The &lt;strong&gt;.env&lt;/strong&gt; file should look like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=zzjudekqvs

DB_USERNAME=zzjudekqvs

DB_PASSWORD=

BROADCAST_DRIVER=log

CACHE_DRIVER=file

SESSION_DRIVER=file

QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1

REDIS_PASSWORD=null

REDIS_PORT=6379

MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME=saquib.gt@gmail.com

MAIL_PASSWORD=

MAIL_ENCRYPTION=tls

PUSHER_APP_ID=

PUSHER_APP_KEY=

PUSHER_APP_SECRET=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now everything is ready. Go to the Application tab in the Cloudways platform and click the Launch Application button. You will be notified through an email.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs5h70y8dktw5zuxe0z26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs5h70y8dktw5zuxe0z26.png" alt="Laravel Notification" width="800" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4h7ekut9vji1wunrt0ir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4h7ekut9vji1wunrt0ir.png" alt="Laravel notification" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Send Notifications Via Slack in Laravel
&lt;/h2&gt;

&lt;p&gt;To create and send notification for Slack, you’ll need to install Guzzle in via Composer. Launch SSH and in the root of the application, run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
composer require guzzlehttp/guzzle

php artisan make:notification Newslack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will need a new class for Slack notifications. For this, go to &lt;strong&gt;app/Notifications/Newslack.php&lt;/strong&gt; and paste the following code.&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;?php&lt;/span&gt;

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

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Bus\Queueable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Notifications\Notification&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Contracts\Queue\ShouldQueue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Notifications\Messages\MailMessage&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Notifications\Messages\SlackMessage&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;Newslack&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Notification&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;

   &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Queueable&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;__construct&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="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;via&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="s1"&gt;'slack'&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;toSlack&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="nc"&gt;SlackMessage&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;content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'A new visitor has visited to your application . $this-&amp;gt;user-&amp;gt;first(1-&amp;gt;name)'&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, &lt;strong&gt;via() **method defines the medium for notification and **toSlack()&lt;/strong&gt; method sends the notification onto Slack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set Incoming Webhook
&lt;/h2&gt;

&lt;p&gt;Now to receive Slack notification, go to &lt;a href="https://%7Byourteam%7D.slack.com/apps" rel="noopener noreferrer"&gt;https://{yourteam}.slack.com/apps&lt;/a&gt;. Choose the "Incoming Webhook" type and add a new configuration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9p46lyt037elu3x9qwca.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9p46lyt037elu3x9qwca.png" alt="Laravel notification" width="800" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the Webhook URL and head back to your Laravel app.&lt;/p&gt;

&lt;p&gt;Your model should implement a &lt;strong&gt;routeNotificationForSlack()&lt;/strong&gt; method that returns this webhook. Therefore go to &lt;strong&gt;app/User.php&lt;/strong&gt; and add the following function in it.&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;routeNotificationForSlack&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="s1"&gt;'your_webhook_url'&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 go to &lt;strong&gt;routes/web.php&lt;/strong&gt; and add the following routes.&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;'/slack'&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="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;App\User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;first&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;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Newslack&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;



   &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"A slack notification has been send"&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 go to the Application tab in the Cloudways platform, click the Launch Application button and add /slack in the url. You will receive Slack notification as shown below:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;Laravel Notification system is a fascinating and very easy to implement feature that adds a lot of value to the project. You can use this example to create your own notification system that integrated into your Laravel app without any issues. If you need any help, you can comment below or DM me on twitter. Happy Coding. &lt;/p&gt;

</description>
      <category>laravel</category>
      <category>webdev</category>
      <category>php</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How To Send Email Using Different Email Service Providers in Laravel</title>
      <dc:creator>Saquib Rizwan</dc:creator>
      <pubDate>Tue, 31 Oct 2017 13:23:52 +0000</pubDate>
      <link>https://forem.com/rizwan_saquib/how-to-send-email-using-different-email-service-providers-in-laravel-9a1</link>
      <guid>https://forem.com/rizwan_saquib/how-to-send-email-using-different-email-service-providers-in-laravel-9a1</guid>
      <description>&lt;p&gt;Laravel has become a popular choice for PHP project development because of the many developer-focused functionalities such as authentication, queues, cron jobs, emailing etc. &lt;/p&gt;

&lt;p&gt;To provide email related functionalities, Laravel provides the Mail function which allows developers to send email through a local or cloud-based service.&lt;/p&gt;

&lt;p&gt;The most efficient and effective way of utilizing the email functionalities is to use the email service instead of manually sending the emails. In this article, I will explain how to send emails in Laravel with the  Mailable function. I will also explain in detail how to setup third party email service providers,  to enhance the email function in Laravel. &lt;/p&gt;

&lt;p&gt;If you are new to Laravel, you can take a look at &lt;a href="https://www.cloudways.com/blog/install-laravel-5-4-localhost/" rel="noopener noreferrer"&gt;getting started with Laravel 5.4&lt;/a&gt;, and introductions to &lt;a href="https://www.cloudways.com/blog/routing-in-laravel-5-4/" rel="noopener noreferrer"&gt;Routing&lt;/a&gt;, &lt;a href="https://www.cloudways.com/blog/controllers-middleware-laravel-5-4/" rel="noopener noreferrer"&gt;Controllers&lt;/a&gt;, &lt;a href="https://www.cloudways.com/blog/models-views-laravel-5-4/" rel="noopener noreferrer"&gt;Models and Views&lt;/a&gt;. &lt;/p&gt;

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

&lt;p&gt;I will start by installing a Laravel application on Cloudways server. The good thing about the process is that it requires just a few clicks to deploy a live application on a cloud server. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2FLaravel_landing-2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fwww.cloudways.com%2Fblog%2Fwp-content%2Fuploads%2FLaravel_landing-2.gif" alt="Deploying Laravel app" width="1024" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Mailables
&lt;/h2&gt;

&lt;p&gt;To setup the basic Laravel mail function, I will use &lt;strong&gt;php artisan command&lt;/strong&gt;. Type the following command in the terminal:&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="n"&gt;php&lt;/span&gt; &lt;span class="n"&gt;artisan&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;mail&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;mailable&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create the mailable class. Next, go to &lt;strong&gt;app/Mail&lt;/strong&gt; and open the mailable file. The default code for the class would look 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="cp"&gt;&amp;lt;?php&lt;/span&gt;



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



&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Bus\Queueable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Mail\Mailable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Queue\SerializesModels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Contracts\Queue\ShouldQueue&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;mailme&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Mailable&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;

   &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Queueable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SerializesModels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;



   &lt;span class="cd"&gt;/**

    * Create a new message 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="n"&gt;__construct&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="p"&gt;}&lt;/span&gt;



   &lt;span class="cd"&gt;/**

    * Build the message.

    *

    * @return $this

    */&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;build&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="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;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;'view.name'&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="nc"&gt;Now&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;following&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 


 &lt;span class="kt"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

   &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="nv"&gt;$address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'saquibrizwan@xyz.com'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

       &lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Saquib Rizwan'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

       &lt;span class="nv"&gt;$subject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Laravel Email'&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;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;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;'emails.mailme'&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;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$name&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;subject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$subject&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;Next, I will create the email template. &lt;/p&gt;

&lt;h2&gt;
  
  
  Create Email Template
&lt;/h2&gt;

&lt;p&gt;Now go to &lt;strong&gt;resources/views&lt;/strong&gt; and create a new folder with the name &lt;strong&gt;emails&lt;/strong&gt; This folder will contain the email template. In the folder, create a new file &lt;strong&gt;mailme.blade.php&lt;/strong&gt; and create the email template using HTML tags.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;h1&amp;gt;Laravel Email&amp;lt;/h1&amp;gt;

 &amp;lt;p&amp;gt;The email has been send&amp;lt;/p&amp;gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuring the Routes
&lt;/h2&gt;

&lt;p&gt;I will now configure the routes which will trigger the email. Go to &lt;strong&gt;routes/web.php&lt;/strong&gt; and paste in the following code:&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;?php&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="n"&gt;App\Mail\mailme&lt;/span&gt;&lt;span class="p"&gt;;&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;'/'&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="p"&gt;{&lt;/span&gt;

    &lt;span class="nc"&gt;Mail&lt;/span&gt;&lt;span class="o"&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;'saquib.rizwan@xyz.com'&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;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;mailme&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;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'emails.mailme'&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 that the route is ready, I will look into the configurations for different email services providers for sending the email. &lt;/p&gt;

&lt;h2&gt;
  
  
  Configurations for Gmail
&lt;/h2&gt;

&lt;p&gt;First of all, login to your Gmail account. Under &lt;strong&gt;My account &amp;gt; Sign In &amp;amp;&lt;/strong&gt; &lt;strong&gt;Security &amp;gt; Sign In&lt;/strong&gt; to Google, enable &lt;strong&gt;two step verification&lt;/strong&gt;, and then generate &lt;strong&gt;app password&lt;/strong&gt;,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fai2raq3lmmhtea58z15j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fai2raq3lmmhtea58z15j.png" alt="Gmail Configurre" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now use the app password in &lt;strong&gt;.env&lt;/strong&gt; file with the following configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME= your.email@gmail.com

MAIL_PASSWORD= your.generated.app.password

MAIL_ENCRYPTION=tls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now go to Cloudways Platform, and launch your application with the help of the free staging domain. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fstqgltzzyrjp2q56hose.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fstqgltzzyrjp2q56hose.png" alt="Staging Domain" width="691" height="501"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And, your email will be sent to the email address which you added to the routes. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2g1k61qodnkyeealsj8a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2g1k61qodnkyeealsj8a.png" alt="Send Email" width="448" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configurations for Mailtrap
&lt;/h2&gt;

&lt;p&gt;First of all go to &lt;a href="https://mailtrap.io/" rel="noopener noreferrer"&gt;Mailtrap.io&lt;/a&gt;. Signup and create your account. Once you have logged in, you will see your dashboard. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fovpdarw5m3jgdxxsc397.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fovpdarw5m3jgdxxsc397.png" alt="Mail trap config" width="800" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on inbox and get your username and password. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmwb94jzkga47ogynbxm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmwb94jzkga47ogynbxm.png" alt="Mail trap config" width="800" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now use these credentials in &lt;strong&gt;.env&lt;/strong&gt; file with the following configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
MAIL_DRIVER="smtp"

MAIL_HOST="mailtrap.io"

MAIL_PORT=2525

MAIL_USERNAME= your.mailtrap.user

MAIL_PASSWORD= your.mailtrap.pass

MAIL_ENCRYPTION=null

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

&lt;/div&gt;



&lt;p&gt;Now go to the Cloudways Platform and launch your application. Your email will be sent to your Mailtrap inbox. &lt;/p&gt;

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

&lt;h2&gt;
  
  
  Configuration for Mailgun
&lt;/h2&gt;

&lt;p&gt;Go to &lt;a href="https://www.mailgun.com/" rel="noopener noreferrer"&gt;Mailgun.com&lt;/a&gt;, signup and create your account. After the login, you will redirected to your dashboard.&lt;/p&gt;

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

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

&lt;p&gt;I will use the Domain and API Key in &lt;strong&gt;.env&lt;/strong&gt; file and add the following lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MAIL_DRIVER="mailgun"

MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox3bafabb2ef66461ab331b8413425ab23.mailgun.org

MAILGUN_SECRET= your_api_key

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

&lt;/div&gt;



&lt;p&gt;Now go to the **routes/web.php **and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
require '../vendor/autoload.php';

use Mailgun\Mailgun;

$mgClient = new Mailgun('your.api.key');

$domain = "sandbox3bafabb2ef66461ab331b8413425ab23.mailgun.org";

# Make the call to the client.

$result = $mgClient-&amp;gt;sendMessage("$domain",

          array('from'    =&amp;gt; 'Mailgun Sandbox &amp;lt;postmaster@sandbox3bafabb2ef66461ab331b8413425ab23.mailgun.org&amp;gt;',

                'to'      =&amp;gt; 'Saquib &amp;lt;saquib.rizwan@xyz.com&amp;gt;',

                'subject' =&amp;gt; 'Hello Saquib',

                'text'    =&amp;gt; 'Congratulations Saquib, you just sent an email with Mailgun!  You are truly awesome! '));

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

&lt;/div&gt;



&lt;p&gt;Finally, go to the root of your application in the terminal and execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require mailgun/mailgun-php php-http/guzzle6-adapter php-http/message
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it. Go to the Cloudways Platform and launch your application using the free staging domain and the email will be sent to your given email address. &lt;/p&gt;

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

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, I demonstrated how you can easily use Laravel mailable for sending emails with different email service providers. If you need help with the code or would like to add to the discussion, do leave a comment below. &lt;/p&gt;

&lt;p&gt;Note: To Host your Laravel application on Digital Ocean server FREE for 2 months,&lt;a href="https://platform.cloudways.com/signup" rel="noopener noreferrer"&gt;Signup&lt;/a&gt; at Cloudways and Use Coupon Code &lt;strong&gt;"PHP15".&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>laravel</category>
      <category>webdev</category>
      <category>php</category>
    </item>
    <item>
      <title>Deploy Laravel Application On Cloud Easily With Cloudways</title>
      <dc:creator>Saquib Rizwan</dc:creator>
      <pubDate>Fri, 15 Sep 2017 11:35:44 +0000</pubDate>
      <link>https://forem.com/rizwan_saquib/deploy-laravel-application-on-cloud-easily-with-cloudways</link>
      <guid>https://forem.com/rizwan_saquib/deploy-laravel-application-on-cloud-easily-with-cloudways</guid>
      <description>&lt;p&gt;Even if you know all about it, setting up and configuring a dedicated server is a time consuming multi-step process. But thanks to managed hosting solutions available in the market today, setting up servers is no longer a major action item on project task lists. &lt;/p&gt;

&lt;p&gt;Deploying Laravel application on cloud infrastructure is never been this fast and easy before. With Cloudways, you can deploy a &lt;strong&gt;dedicated cloud server&lt;/strong&gt; with your required resources in just a few clicks! Cloudways offers server infrastructure from five top providers - &lt;strong&gt;Amazon, DigitalOcean, Vultr, KYUP and Google Compute Engine&lt;/strong&gt;. On top of that, the hosting platform is uniquely optimized for Laravel developers!&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloudways for Laravel
&lt;/h2&gt;

&lt;p&gt;Cloudways provides an incredible platform for Laravel Community. It makes it easy to deploy and host laravel applications so that developers can focus on the development process rather than worrying about deployment and server level issues. &lt;/p&gt;

&lt;p&gt;Cloudways take cares of the hosting pain points of Laravel developers through the following features: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Server Cost is included in the Cloudways price plan. Hence developers only need a single account and receive a single invoice. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easily deploy Laravel applications from &lt;strong&gt;Github&lt;/strong&gt; or &lt;strong&gt;Bitbucket&lt;/strong&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Auto deployment for Laravel applications.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Team Collaboration feature assigns server and application access and roles to the members of the team. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easy server management features including server cloning and server transfer. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;One click auto backup with frequency ranging from hourly to weekly. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure scheduled cron jobs with cron job manager&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pre-configured firewall and security&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Monitor everything with the &lt;strong&gt;New Relic&lt;/strong&gt; monitoring system. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scale up servers with easy vertical scaling.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pre-installed &lt;strong&gt;Composer and Git&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;24x7 live chat support by cloud professionals.  &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Cloudways ThunderStack
&lt;/h2&gt;

&lt;p&gt;Cloudways has its own PHP stack called ThunderStack that consists of unique mix of server and caching technologies. Each server launched on the Cloudways Platform comes with: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Debian&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nginx&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Varnish&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apache&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PHP-FPM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MySQL or MariaDB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Redis&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Memcached&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PHP 5.6 or 7.0 &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cloudways supports all major PHP frameworks including Laravel, Symfony, Codegniter and CakePHP, and allows &lt;strong&gt;one-click installation&lt;/strong&gt; of your favorite PHP-based CMS like WordPress and Bolt.  &lt;/p&gt;

&lt;p&gt;Let’s run through a sample case of setting up PHP 7 on a DigitalOcean server using the Cloudways Platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy the Server
&lt;/h2&gt;

&lt;p&gt;To set up a PHP 7 server on DigitalOcean at Cloudways, simply &lt;a href="https://platform.cloudways.com/signup" rel="noopener noreferrer"&gt;sign up&lt;/a&gt; at Cloudways and login to your account.&lt;/p&gt;

&lt;p&gt;Go to Launch server. Select your PHP stack, DigitalOcean as your infrastructure provider and identify your server resource needs along with other required details.&lt;/p&gt;

&lt;p&gt;And you’re done! Your Digital Ocean server will now be deployed within minutes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Use promo code&lt;/strong&gt;** PHP15**** to get *&lt;strong&gt;&lt;em&gt;$15 free credit *&lt;/em&gt;&lt;/strong&gt;in your Cloudways account. **&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4lcupv91sewfvewo6ogj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4lcupv91sewfvewo6ogj.gif" alt="Cloudways Application Launch" width="1024" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy Your Laravel App From GitHub
&lt;/h2&gt;

&lt;p&gt;As a developer, you likely have your Laravel application on a GitHub repository. You can easily deploy it on your Cloudways server in a matter of minutes. &lt;/p&gt;

&lt;p&gt;To deploy the application from a Git repo, first, in the Platform dashboard, click the ‘&lt;strong&gt;Applications&lt;/strong&gt;’ tab from the top menu bar and select your application. Now, in order to deploy the application, you will now need an SSH key. &lt;/p&gt;

&lt;p&gt;To generate the SSH key, click on the ‘&lt;strong&gt;Deployment via Git&lt;/strong&gt;’ button on the ‘&lt;strong&gt;Application Management&lt;/strong&gt;’ area and then click the ‘&lt;strong&gt;Generate SSH Keys&lt;/strong&gt;’ button to generate your unique SSH key. To download these keys, simply click ‘&lt;strong&gt;Download SSH Keys&lt;/strong&gt;’. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7nm2gidhrfasmgx0wsv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr7nm2gidhrfasmgx0wsv.png" alt="Deploy with git" width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now upload the ‘&lt;strong&gt;SSH Public Key’&lt;/strong&gt; to your GitHub account. In order to do this, login to your GitHub account, go to the desired repository, and then into the ‘&lt;strong&gt;Settings&lt;/strong&gt;’ tab. Click the ‘&lt;strong&gt;Add Deploy Key&lt;/strong&gt;’ button and add the &lt;strong&gt;Public SSH Key **which you have downloaded from Cloudways platform. Click the ‘&lt;/strong&gt;Add Key**’ button to finalize the process. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7kp9olvsu8vq38ttb3r7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7kp9olvsu8vq38ttb3r7.png" alt="Deploy with Git 2" width="800" height="553"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now copy the ‘&lt;strong&gt;Repository SSH Address&lt;/strong&gt; that you will see in the top panel in your main GitHub dashboard. Copy and paste this address in your Cloudways’ ‘&lt;strong&gt;Git Remote Address&lt;/strong&gt;’ field.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fer7dv0dzxw6n1qn0rgo3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fer7dv0dzxw6n1qn0rgo3.png" alt="Deploy Laravel With Git on Cloud" width="800" height="266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, you need to input the deployment path and click on ‘&lt;strong&gt;Start Deployment&lt;/strong&gt;’ button to have your application code deployed onto the Cloudways platform!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjjf902r8t4tqqq7ckvc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjjf902r8t4tqqq7ckvc1.png" alt="Deploy Laravel With Git on Cloud" width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s It! Cloudways makes it's that easy to deploy your Laravel application on the cloud infrastructure of your choice. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As you can see, you can easily deploy your Laravel application with Cloudways. It allows you to easily handle some of the most important Laravel application hosting issues. From setting up your server and server resources initially, deploying your application, to managing backend application tasks, everything is done effortlessly with Cloudways! &lt;/p&gt;

&lt;p&gt;Click &lt;a href="https://www.cloudways.com/en/" rel="noopener noreferrer"&gt;HERE&lt;/a&gt; to get started with Cloudways right away! &lt;/p&gt;

</description>
      <category>laravel</category>
      <category>webdev</category>
      <category>cloud</category>
      <category>hosting</category>
    </item>
    <item>
      <title>How to Create LAMP stack with Laravel on Digital Ocean Server </title>
      <dc:creator>Saquib Rizwan</dc:creator>
      <pubDate>Wed, 23 Aug 2017 09:28:18 +0000</pubDate>
      <link>https://forem.com/rizwan_saquib/how-to-create-lamp-stack-with-laravel-on-digital-ocean-server</link>
      <guid>https://forem.com/rizwan_saquib/how-to-create-lamp-stack-with-laravel-on-digital-ocean-server</guid>
      <description>&lt;p&gt;Laravel has become the PHP framework of choice for projects of all scopes. From a simple web app to huge corporate portals, laravel is up for tasks of all scopes. The robust framework is very versatile and is supported by a very passionate community of developers and users. One good thing about Laravel is the fact that it is easy to install and is compatible with all development environments except one exception; the installation of Laravel framework on cloud servers. &lt;/p&gt;

&lt;p&gt;In this tutorial, I will take you through the steps required to setup a Laravel powered LAMP stack on Ubuntu. For the purpose of this tutorial, I will be using DigitalOcean (DO) cloud server running Ubuntu 16.04.2. &lt;/p&gt;

&lt;h2&gt;
  
  
  Connect to DO Cloud Server
&lt;/h2&gt;

&lt;p&gt;The most common and convenient way of connecting to cloud servers is through Secure Shell (SSH). This shell offers a secure and safe communication channel for connecting to and executing commands on the cloud server. &lt;/p&gt;

&lt;p&gt;SSH comes pre built in Linux environments. For MS Windows, you can use &lt;a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html" rel="noopener noreferrer"&gt;PuTTY&lt;/a&gt; to enable them. To connect to the cloud server, you must have the following credentials: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Server IP address&lt;/li&gt;
&lt;li&gt;Username &lt;/li&gt;
&lt;li&gt;Password or SSH key &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Fire up PuTTY and fill in the server IP address. &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%2Fcdn.filestackcontent.com%2FkZRwprtKR3KDlvrNmfmb" 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%2Fcdn.filestackcontent.com%2FkZRwprtKR3KDlvrNmfmb" alt="image14.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Open&lt;/strong&gt;. You will see a security alert notifying that you have not connected to this server before. If you are sure that you have got the IP address right, click &lt;strong&gt;Yes&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%2Fcdn.filestackcontent.com%2FpEJUNnnRRSjWx8KN8bgS" 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%2Fcdn.filestackcontent.com%2FpEJUNnnRRSjWx8KN8bgS" alt="image15.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, insert the login credentials (username and password)) for the server. &lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; You will not be able to see the password in the console screen. &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%2Fcdn.filestackcontent.com%2FNCG7tCoSzeerrnnXH7JI" 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%2Fcdn.filestackcontent.com%2FNCG7tCoSzeerrnnXH7JI" alt="image12.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that you have inputted your username and password, you should be successfully connected to the server.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to the LAMP Stack
&lt;/h2&gt;

&lt;p&gt;A LAMP stack is an integrated and interconnected setup of open source software. The setup comprises of &lt;strong&gt;L&lt;/strong&gt;inux, &lt;strong&gt;A&lt;/strong&gt;pache web server, &lt;strong&gt;M&lt;/strong&gt;ySQL which is an open source RDBMS and &lt;strong&gt;P&lt;/strong&gt;HP. &lt;/p&gt;

&lt;p&gt;LAMP stack is perhaps the most common solution for setting up servers for web development. An important reason for this universal choice is the cost factor - all components of the LAMP stack are free to use. In addition, the communities behind individual components are very active and patches and updates are frequently released to ensure that everything is in top working order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check Updates for Packages
&lt;/h2&gt;

&lt;p&gt;Before going ahead with the LAMP stack installation, update all the packages available on the server. In order to do that, use the following command: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ apt-get update&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ apt-get upgrade&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ apt-get dist-upgrade&lt;/code&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%2Fcdn.filestackcontent.com%2Fifr993zPQjm3hjMIfNmQ" 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%2Fcdn.filestackcontent.com%2Fifr993zPQjm3hjMIfNmQ" alt="image9.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is an important step because the latest version of all the packages ensure that the rest of the process and the subsequent Laravel development process goes without a hitch.&lt;/p&gt;

&lt;p&gt;Let’s start with deploying the LAMP stack! We begin with installing the Apache web server. &lt;/p&gt;

&lt;h2&gt;
  
  
  Install the Apache Web Server
&lt;/h2&gt;

&lt;p&gt;Apache is an open source web server that hosts approximately 50% of the websites on the internet. To install Apache server on the DO cloud server, use the following command: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ apt-get install apache2&lt;/code&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%2Fcdn.filestackcontent.com%2FYP9VzwtSE2jlLOUocfKx" 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%2Fcdn.filestackcontent.com%2FYP9VzwtSE2jlLOUocfKx" alt="image4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;During the installation process, you might be asked about the requirement for additional disk space. Press &lt;strong&gt;Y&lt;/strong&gt; and Apache installation process will resume.  &lt;/p&gt;

&lt;p&gt;Once the installation is over, launch your browser and enter the server’s IP address in the address bar. In the case of successful installation, you should see the following page:&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%2Fcdn.filestackcontent.com%2FabJmJKAeQei2NQJM1fJT" 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%2Fcdn.filestackcontent.com%2FabJmJKAeQei2NQJM1fJT" alt="image3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, Apache is configured to run server script located in the &lt;strong&gt;/var/www/html&lt;/strong&gt; folder. To change this behavior and ensure that the server executes scripts from &lt;strong&gt;public_html&lt;/strong&gt; folder. I will configure the &lt;strong&gt;000-default.conf&lt;/strong&gt; file (located in the apache2/sites-enabled folder. Use the following command to navigate to this folder: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ cd /etc/apache2/sites-enabled&lt;/code&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%2Fcdn.filestackcontent.com%2FFKTCmlxYRlOsHgv5a6Te" 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%2Fcdn.filestackcontent.com%2FFKTCmlxYRlOsHgv5a6Te" alt="image1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to open up the config file in Vim, use the following command: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ vim 000-default.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Locate the entry for &lt;strong&gt;DocumentRoot&lt;/strong&gt;, press &lt;strong&gt;i&lt;/strong&gt; to edit the file, and then replace &lt;strong&gt;html&lt;/strong&gt; with &lt;strong&gt;public_html&lt;/strong&gt;. Check the screenshot below:&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%2Fcdn.filestackcontent.com%2F8MDHnENcSHeWHxxaHdTx" 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%2Fcdn.filestackcontent.com%2F8MDHnENcSHeWHxxaHdTx" alt="image8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When done, press Esc and then press &lt;strong&gt;:wq&lt;/strong&gt; to save and exit the editor. Next, rename the &lt;strong&gt;/var/www/html&lt;/strong&gt; folder to &lt;strong&gt;public_html&lt;/strong&gt;.  For this, use the following set of commands:  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ cd /var/www&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ mv html public_html&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ ls&lt;/code&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%2Fcdn.filestackcontent.com%2FUTuOeDVZToRoI8c2vIwJ" 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%2Fcdn.filestackcontent.com%2FUTuOeDVZToRoI8c2vIwJ" alt="image2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, that I have a working public_html folder, restart the web server services with the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ service apache2 restart&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To try out the new settings, re-enter the IP address in the browser. You should see the Welcome Page of the Apache server. Your Apache server is up and running!&lt;/p&gt;

&lt;h2&gt;
  
  
  Install MySQL DBMS
&lt;/h2&gt;

&lt;p&gt;Now let’s install the MySQL which is a popular relational database management system that usually powers PHP applications. &lt;/p&gt;

&lt;p&gt;To install MySQL on the cloud server, go to the root folder and initiate the installation process by entering the following commands: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ cd&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;code&gt;$ apt-get install mysql-server&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The process will pause to ask your permission. Type &lt;strong&gt;Y&lt;/strong&gt; and press enter. In the next window, set the password of MySQL root user. &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%2Fcdn.filestackcontent.com%2F10p7pUpQKu6FYhRa2Tvy" 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%2Fcdn.filestackcontent.com%2F10p7pUpQKu6FYhRa2Tvy" alt="image10.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The process finishes in a matter of moments. Next, I will configure MySQL according to the requirements of the LAMP stack. Enter the following command: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ mysql_secure_installation&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The command will ask you to enter the password for the root. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You will not be able to see the password when you enter it. &lt;/p&gt;

&lt;p&gt;Next, set the following configurations: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Press &lt;strong&gt;Y&lt;/strong&gt; to to setup Validate Password plugin.&lt;/li&gt;
&lt;li&gt;Select the level of password validation policy. (I selected the lowest for the * purpose of this tutorial). &lt;/li&gt;
&lt;li&gt;Enter &lt;strong&gt;N&lt;/strong&gt; in order not to change the root password and hit Enter, then type &lt;strong&gt;Y&lt;/strong&gt; to remove anonymous users and hit Enter.&lt;/li&gt;
&lt;li&gt;Type &lt;strong&gt;N&lt;/strong&gt; if you want to disallow root login remotely and hit Enter.&lt;/li&gt;
&lt;li&gt;Now type &lt;strong&gt;Y&lt;/strong&gt; to remove test tables and databases and hit Enter, and then type &lt;strong&gt;Y&lt;/strong&gt; again and hit Enter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you are done with these steps, you should see &lt;strong&gt;All done!&lt;/strong&gt; on the screen. &lt;strong&gt;MySQL&lt;/strong&gt; database management system is now successfully installed and configured. &lt;/p&gt;

&lt;h2&gt;
  
  
  Install PHP
&lt;/h2&gt;

&lt;p&gt;Now we go about installing PHP. Short for Hypertext Preprocessor, PHP is an open source web scripting language that is ideal for creating dynamic websites. To Install the latest version of PHP on your server, type the following command: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$  apt install php7.0-cli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will install PHP on the server. In the beginning of the process, you might be asked whether you want to continue? Press &lt;strong&gt;Y&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%2Fcdn.filestackcontent.com%2F2GuRjCfT9C02boJaHExW" 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%2Fcdn.filestackcontent.com%2F2GuRjCfT9C02boJaHExW" alt="image6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the installation finishes, install the &lt;strong&gt;lib_apache2 mod&lt;/strong&gt; for PHP. Next, restart the Apache service. Use the following commands for these two tasks:  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ apt install libapache2-mod-php7.0&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ service apache2 restart&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Go to the &lt;strong&gt;public_html&lt;/strong&gt; folder and create a simple PHPinfo file. Use the following commands:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ cd&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ cd /var/www/public_html&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ rm index.html&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ vim index.php&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, press &lt;strong&gt;I&lt;/strong&gt; and type in the following code: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;?php echo phpinfo(); ?&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Save it by pressing &lt;strong&gt;Esc&lt;/strong&gt; and type &lt;strong&gt;:wq&lt;/strong&gt; to save and exit. Now test this file by entering the server IP Address in the browser’s address bar. You should see something like this: &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%2Fcdn.filestackcontent.com%2FKuqKUQLCRkKu7i8v83Cy" 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%2Fcdn.filestackcontent.com%2FKuqKUQLCRkKu7i8v83Cy" alt="image5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, the &lt;strong&gt;LAMP&lt;/strong&gt; stack has been successfully installed on the &lt;strong&gt;DO cloud&lt;/strong&gt; server. However, there is still some work left to do. &lt;/p&gt;

&lt;h2&gt;
  
  
  Install PHPmyAdmin
&lt;/h2&gt;

&lt;p&gt;Developers require a UI to manage MySQL. PHPmyAdmin is one of the most popular open source GUI for MySQL. To setup PHPmyAdmin on the server, execute the following commands: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ apt-get install php7.0-mbstring&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ apt-get install mcrypt&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ service apache2 restart&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ apt-get install phpmyadmin&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The process will ask you to select the server for installation. Select &lt;strong&gt;Apache&lt;/strong&gt; and press Enter. Next, provide your MySQL credentials. PHPMyAdmin will be installed at &lt;strong&gt;/usr/share/phpmyadmin&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Next, I will create the relevant symlink inside the public_html folder. Type the following commands to go to the public_html folder and create the symlink:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ cd&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ cd /var/www/public_html&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ ln -s /usr/share/phpmyadmin&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ ls&lt;/code&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%2Fcdn.filestackcontent.com%2FIO5uTdCUSAuVEiv51lve" 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%2Fcdn.filestackcontent.com%2FIO5uTdCUSAuVEiv51lve" alt="image13.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now enter &lt;strong&gt;your_server_ip / phpmyadmi&lt;/strong&gt;n in the browser. You will see PHPmyAdmin’s login form: &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%2Fcdn.filestackcontent.com%2FOXSFMO1cQfWU4RGone4t" 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%2Fcdn.filestackcontent.com%2FOXSFMO1cQfWU4RGone4t" alt="image11.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, I will secure it by creating a &lt;strong&gt;.htaccess&lt;/strong&gt; file using Vim inside PHPMyAdmin folder. This security measure will ensure that only allow your server’s IP communicates with PHPMyAdmin:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ cd phpmyadmin&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ vim .htaccess&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Press &lt;strong&gt;I&lt;/strong&gt; and type in the following code: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;order allow,deny&lt;/code&gt;&lt;br&gt;
&lt;code&gt;allow from &amp;lt;your server ip&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The LAMP stack is now ready for your Laravel project! But before you start working on your project, it is important to go about setting up some preliminary resources that you will need for your development project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Git and Composer
&lt;/h2&gt;

&lt;p&gt;Git and Composer are two essential resources for working with Laravel. Git is a free and open source distributed version control system designed to handle a host of projects. The Composer is a very useful tool to help manage dependencies in PHP. The Composer enables you to declare the libraries that your project is dependent on and it will manage them for you.&lt;/p&gt;

&lt;p&gt;I will begin with the installation of git using a simple command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ apt-get install git-all&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command is all you need to get the git going for your Laravel project.&lt;/p&gt;

&lt;p&gt;Now I will install &lt;a href="https://getcomposer.org/download/" rel="noopener noreferrer"&gt;Composer&lt;/a&gt; and move it to the &lt;strong&gt;Bin&lt;/strong&gt; folder so that I could use it on command line.  Use the following commands for the process:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ php composer-setup.php&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ php -r "unlink('composer-setup.php');"&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ apt install composer&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Laravel Using Composer
&lt;/h2&gt;

&lt;p&gt;Now to install Laravel, head to &lt;strong&gt;public_html&lt;/strong&gt; folder and type the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ cd&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ cd /var/www/public_hmtl&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ composer create-project --prefer-dist laravel/laravel myapplication&lt;/code&gt;&lt;br&gt;
&lt;code&gt;$ cd myapplication&lt;/code&gt; &lt;br&gt;
&lt;code&gt;$ chmod 777 -R storage/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;At this point, Laravel is installed and ready for use. To test the success of the installation, type &lt;strong&gt;your_server_Ip_address/myapplication/public&lt;/strong&gt; in your browser. You will see the Laravel welcome page. &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%2Fcdn.filestackcontent.com%2FvkfUughNSEub6zJCASgu" 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%2Fcdn.filestackcontent.com%2FvkfUughNSEub6zJCASgu" alt="image7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying Laravel On Managed Hosting Platform
&lt;/h2&gt;

&lt;p&gt;As you can see this is a perfectly legitimate but a long and tedious process of setting up a server directly on the cloud host. Not to mention the constant need of monitoring and maintaining your server! . &lt;/p&gt;

&lt;p&gt;To experience high performing stacks, easy deployment process and hassle-free management and monitoring of your server and related resources, your best bet is signing up with a &lt;a href="https://www.cloudways.com/en/laravel-hosting.php" rel="noopener noreferrer"&gt;managed laravel hosting&lt;/a&gt; provider like Cloudways.&lt;/p&gt;

&lt;p&gt;Cloudways has one of the best PHP stacks in the industry comprising of Nginx, Varnish, Apache, PHP-FPM, Memcached/Redis, MySQL, and full PHP 7 support. You can host your application to (Google,Amazon,Digital Ocean,Vultr and Kyup) in just &lt;strong&gt;few clicks.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;There are also attractive discount offers and free credit. For example, using the coupon code: &lt;strong&gt;WPMUDEV&lt;/strong&gt; gets you $50 credit for free!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, I introduced LAMP stack and then discussed the installation of the stack on DO cloud servers running Ubuntu. I next installed Laravel on the LAMP stack and then followed it up with mentioning a quicker alternative you can use to ready your Laravel environment using Cloudways. &lt;/p&gt;

&lt;p&gt;Do note however, that LAMP stack is the most basic setup on any server that let's you run a PHP based website. But the industry has fast evolved to restrict LAMP stack as really a basic solution only. Other popular solutions use LEMP stack where Apache is replaced with the lightweight and powerful Nginx or a stack that utilizes Nginx and Apache together, with powerful caching technologies like Varnish cache etc.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>cloudhosting</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Laravel Contact Form With Email</title>
      <dc:creator>Saquib Rizwan</dc:creator>
      <pubDate>Mon, 17 Jul 2017 10:05:57 +0000</pubDate>
      <link>https://forem.com/rizwan_saquib/laravel-contact-form-with-email</link>
      <guid>https://forem.com/rizwan_saquib/laravel-contact-form-with-email</guid>
      <description>&lt;p&gt;Laravel is a popular PHP framework for creating dynamic websites and web application. Laravel offers a wide range of functionalities that take care of routine project requirements such as routing, authentication, sessions and caching. A Contact Us form is another routine functionality present at all websites these days. &lt;/p&gt;

&lt;p&gt;In this article, I am going to show you how to easily create a contact form in Laravel with email. &lt;/p&gt;

&lt;h2&gt;
  
  
  Install Laravel Application
&lt;/h2&gt;

&lt;p&gt;For demonstrating the Laravel contact form, I will be creating and &lt;a href="https://www.cloudways.com/en/laravel-hosting.php" rel="noopener noreferrer"&gt;hosting Laravel&lt;/a&gt; application on Cloudways. Sign up at Cloudways for free and login to your account. Next: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new server. &lt;/li&gt;
&lt;li&gt;Fill in the server and the application details and select Laravel as the application. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s it, within a few clicks you have installed and setup a fully functional Laravel application.&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%2Fuploads%2Farticles%2F4lcupv91sewfvewo6ogj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4lcupv91sewfvewo6ogj.gif" alt="Install Laravel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Laravel Collective HTML Package
&lt;/h2&gt;

&lt;p&gt;To create the form in Laravel, install the &lt;strong&gt;laravelcollective/html&lt;/strong&gt; package for Form facade. Go to the Cloudways platform and open the Server tab. Launch the SSH terminal and login to your server using the Master Credentials.&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%2Fuploads%2Farticles%2F6iu6hwwenw95v9hj7nr5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6iu6hwwenw95v9hj7nr5.png" alt="Launch SSH"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now go to the root of your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd applications
cd applicationname/public_html
composer require laravelcollective/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the package is installed, goto &lt;strong&gt;config/app.php&lt;/strong&gt; file and add the service provider and alias:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;config/app.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="s1"&gt;'providers'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="mf"&gt;....&lt;/span&gt;
&lt;span class="s1"&gt;'Collective\Html\HtmlServiceProvider'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="s1"&gt;'aliases'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="mf"&gt;....&lt;/span&gt;
&lt;span class="s1"&gt;'Form'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Collective\Html\FormFacade'&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;h2&gt;
  
  
  Database Configuration
&lt;/h2&gt;

&lt;p&gt;The next step is to configure the database. Open the Application tab in the Cloudways platform and go to Application Access details. Use these database credentials. &lt;/p&gt;

&lt;p&gt;Go to the .env file (located in the application public root folder) and add the credentials there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= your.database.name                                                                                                                            
DB_USERNAME= your.database.username                                                                                                                             
DB_PASSWORD= your.database.password

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create Migrations for Contact Us Table
&lt;/h2&gt;

&lt;p&gt;Go to the public root folder of the application and run the following command to create the database migration for creating the Contact Us model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:migration create_contact_us_table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That will create the migration. &lt;/p&gt;

&lt;p&gt;After that, go to &lt;strong&gt;database/migration/date_ create_contact_us_table.php&lt;/strong&gt; and add the following code to it.&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;?php&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Support\Facades\Schema&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Database\Schema\Blueprint&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Database\Migrations\Migration&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;CreateContactUsTable&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Migration&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/**
     * Run the migrations.
     *
     * @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="n"&gt;up&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'contactus'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Blueprint&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;increments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;timestamps&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="cd"&gt;/**
     * Reverse the migrations.
     *
     * @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="n"&gt;down&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"contactus"&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 run the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create the Model
&lt;/h2&gt;

&lt;p&gt;Go to the public root folder of the application and type in the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:model ContactUS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After successfully creating the ContactUS model, go to app/ContactUS.php and add the following code in the 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="cp"&gt;&amp;lt;?php&lt;/span&gt;

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

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Database\Eloquent\Model&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;ContactUS&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$table&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'contactus'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nv"&gt;$fillable&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="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'message'&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;h2&gt;
  
  
  Create the Route
&lt;/h2&gt;

&lt;p&gt;Go to &lt;strong&gt;routes/web.php&lt;/strong&gt; and add the following code to the route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::get('contact-us', 'ContactUSController@contactUS');
Route::post('contact-us', ['as'=&amp;gt;'contactus.store','uses'=&amp;gt;'ContactUSController@contactUSPost']);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create the Controller
&lt;/h2&gt;

&lt;p&gt;Now create a controller for handling the requests from the routes. Now go to &lt;strong&gt;app/Http/Controllers/ContactUSController.php&lt;/strong&gt; and add the following code to it:&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;?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="nc"&gt;Illuminate\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Http\Requests&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\ContactUS&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;ContactUSController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Controller&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="cd"&gt;/**
    * Show the application dashboard.
    *
    * @return \Illuminate\Http\Response
    */&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;contactUS&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;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'contactUS'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="cd"&gt;/**
    * Show the application dashboard.
    *
    * @return \Illuminate\Http\Response
    */&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;contactUSPost&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="nv"&gt;$this&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="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="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="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;'message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required'&lt;/span&gt;
        &lt;span class="p"&gt;]);&lt;/span&gt;

       &lt;span class="nc"&gt;ContactUS&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;all&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;back&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;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'success'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Thanks for contacting us!'&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;h2&gt;
  
  
  Create the View
&lt;/h2&gt;

&lt;p&gt;Everything is now ready and I will now create the layout of the form.  Go to &lt;strong&gt;resources/views/&lt;/strong&gt; and create a file contactUS.blade.php. Place the following code in it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&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&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;title&amp;gt;&lt;/span&gt;Laravel 5.4 Cloudways Contact US Form Example&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&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;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;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Contact US Form&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;

@if(Session::has('success'))
   &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;"alert alert-success"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     {{ Session::get('success') }}
   &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
@endif

{!! Form::open(['route'=&amp;gt;'contactus.store']) !!}

&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;"form-group {{ $errors-&amp;gt;has('name') ? 'has-error' : '' }}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
{!! Form::label('Name:') !!}
{!! Form::text('name', old('name'), ['class'=&amp;gt;'form-control', 'placeholder'=&amp;gt;'Enter Name']) !!}
&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-danger"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ $errors-&amp;gt;first('name') }}&lt;span class="nt"&gt;&amp;lt;/span&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-group {{ $errors-&amp;gt;has('email') ? 'has-error' : '' }}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
{!! Form::label('Email:') !!}
{!! Form::text('email', old('email'), ['class'=&amp;gt;'form-control', 'placeholder'=&amp;gt;'Enter Email']) !!}
&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-danger"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ $errors-&amp;gt;first('email') }}&lt;span class="nt"&gt;&amp;lt;/span&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-group {{ $errors-&amp;gt;has('message') ? 'has-error' : '' }}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
{!! Form::label('Message:') !!}
{!! Form::textarea('message', old('message'), ['class'=&amp;gt;'form-control', 'placeholder'=&amp;gt;'Enter Message']) !!}
&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-danger"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ $errors-&amp;gt;first('message') }}&lt;span class="nt"&gt;&amp;lt;/span&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"form-group"&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;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-success"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Contact US!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

{!! Form::close() !!}

&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;The contact form is now functional.&lt;/p&gt;

&lt;p&gt;On submitting the form, the data will be stored in the database. The next step is of make the form email the information.&lt;/p&gt;

&lt;p&gt;Now create another view, &lt;strong&gt;email.blade.php&lt;/strong&gt; and add the following code in it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You received a message from : {{ $name }}

&amp;lt;p&amp;gt;
Name: {{ $name }}
&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;
Email: {{ $email }}
&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;
Message: {{ $user_message }}
&amp;lt;/p&amp;gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Sending the Email
&lt;/h2&gt;

&lt;p&gt;To understand the steps involved in this step, read &lt;a href="https://www.cloudways.com/blog/send-email-in-laravel/" rel="noopener noreferrer"&gt;sending email in Laravel&lt;/a&gt;.  Now that you have read the steps, it is time to implement the process. First, setup the basic Laravel mail function through PHP Artisan. Use the following command in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:mail &amp;lt;name of mailable&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, login to your Gmail account. Under My account &amp;gt; Sign In And Security &amp;gt; Sign In to Google, enable two-step verification, and then generate the app password. Next, add the app password in the  .env file with the following configurations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME= your.email@gmail.com

MAIL_PASSWORD= your.generated.app.password

MAIL_ENCRYPTION=tls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the configuration is done, update &lt;strong&gt;ContactUsController.php&lt;/strong&gt; with the following code:&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;?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="nc"&gt;Illuminate\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Http\Requests&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\ContactUS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Mail&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;ContactUSController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&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="n"&gt;contactUS&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;view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'contactUS'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
   &lt;span class="cd"&gt;/** * Show the application dashboard. * * @return \Illuminate\Http\Response */&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;contactUSPost&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="nv"&gt;$this&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="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="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="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;'message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required'&lt;/span&gt; &lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="nc"&gt;ContactUS&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;all&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; 

    &lt;span class="nc"&gt;Mail&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="k"&gt;array&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;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;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;'name'&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="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;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'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
           &lt;span class="s1"&gt;'user_message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;)&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;$message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'saquib.gt@gmail.com'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="nv"&gt;$message&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;'saquib.rizwan@cloudways.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Admin'&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;subject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Cloudways Feedback'&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;back&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;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'success'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Thanks for contacting us!'&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;The contact form is now ready for deployment. It will save the data in the database and email it to the given email address as well. To test the Contact Us form, go to the application and click on Launch Application (remember to add /contact-us to the URL).&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%2Fuploads%2Farticles%2F9y2deeb86zpw3swgwglu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9y2deeb86zpw3swgwglu.png" alt="Launch App"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check the &lt;a href="http://phplaravel-77728-284364.cloudwaysapps.com/contact-us" rel="noopener noreferrer"&gt;DEMO&lt;/a&gt; to see the application in action.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Final Words
&lt;/h2&gt;

&lt;p&gt;In this tutorial, I showed you how to create a contact form in Laravel with the functionality of emailing the information to a prespecified email address. &lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
    </item>
    <item>
      <title>Database Level CRUD Operations Using PDO</title>
      <dc:creator>Saquib Rizwan</dc:creator>
      <pubDate>Mon, 22 May 2017 10:58:08 +0000</pubDate>
      <link>https://forem.com/rizwan_saquib/database-level-crud-operations-using-pdo</link>
      <guid>https://forem.com/rizwan_saquib/database-level-crud-operations-using-pdo</guid>
      <description>&lt;p&gt;No real world PHP application could function without a database.&lt;/p&gt;

&lt;p&gt;This is why PHP offers three powerful ways of manipulating and interacting with databases. The list comprises of &lt;em&gt;MySQL&lt;/em&gt;, &lt;em&gt;MySQLi&lt;/em&gt; and &lt;em&gt;PDO&lt;/em&gt;.  &lt;/p&gt;

&lt;p&gt;To remove all the problems caused by these different database management approaches, PHP has standardized PHP Data Objects (PDO) as the database layer of choice. PDO provides easy and very streamlined interface for interacting with the databases in the PHP applications. To work with PDO, the database specific driver(s) must be installed. &lt;/p&gt;

&lt;h1&gt;
  
  
  Supported Databases
&lt;/h1&gt;

&lt;p&gt;PDO supports all popular databases through specific drivers. In effect, the following database drivers are available in PDO. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cubrid (PDO_CUBRID)&lt;/li&gt;
&lt;li&gt;FreeTDS / Microsoft SQL Server / Sybase (PDO_DBLIB)&lt;/li&gt;
&lt;li&gt;Firebird (PDO_FIREBIRD)&lt;/li&gt;
&lt;li&gt;IBM DB2 (PDO_IBM) &lt;/li&gt;
&lt;li&gt;IBM Informix Dynamic Server (PDO_INFORMIX)&lt;/li&gt;
&lt;li&gt;MySQL 3.x/4.x/5.x (PDO_MYSQL)&lt;/li&gt;
&lt;li&gt;Oracle Call Interface(PDO_OCI) &lt;/li&gt;
&lt;li&gt;ODBC v3 (IBM DB2, unixODBC and win32 ODBC) (PDO_ODBC)&lt;/li&gt;
&lt;li&gt;PostgreSQL (PDO_PGSQL)&lt;/li&gt;
&lt;li&gt;SQLite 3 and SQLite 2 (PDO_SQLITE)&lt;/li&gt;
&lt;li&gt;Microsoft SQL Server / SQL Azure (PDO_SQLSRV)&lt;/li&gt;
&lt;li&gt;4D (PDO_4D).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By default, PHP has a PDO_SQLite driver installed. However, if you wish to work with other databases, &lt;a href="http://php.net/manual/en/pdo.installation.php"&gt;you must first install the relevant driver&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;In order to check which drivers are installed on your system, create a new PHP file, and add the following code to it:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
print_r(PDO::getAvailableDrivers());
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Performing CRUD Operations Through PDO
&lt;/h1&gt;

&lt;p&gt;PDO is the best way of performing CRUD and related DBMS operations in PHP because PDO standardizes code that can be reused without major issues. In effect, PDO acts as an abstraction layer that separates database related operations from the rest of the code. &lt;/p&gt;
&lt;h2&gt;
  
  
  Database Connections
&lt;/h2&gt;

&lt;p&gt;Connectivity in PDO is simple. Consider the following code snippet that is used to set up connections with a database. Note that when the underlying database changes, the only change that you need to make in this code is the &lt;a href="https://www.cloudways.com/blog/mysql-data-types/"&gt;database type&lt;/a&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="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kd"&gt;Class&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="k"&gt;private&lt;/span&gt;  &lt;span class="nv"&gt;$server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"mysql:host=localhost;dbname=cloudways"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt;  &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"root"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt;  &lt;span class="nv"&gt;$pass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$options&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ATTR_ERRMODE&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ERRMODE_EXCEPTION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ATTR_DEFAULT_FETCH_MODE&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;FETCH_ASSOC&lt;/span&gt;&lt;span class="p"&gt;,);&lt;/span&gt;
&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$con&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;openConnection&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
       &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;try&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="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PDO&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="n"&gt;server&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="n"&gt;user&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="n"&gt;pass&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="n"&gt;options&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;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
             &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDOException&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
             &lt;span class="p"&gt;{&lt;/span&gt;
                                                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"There is some problem in connection: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
              &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;closeConnection&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="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&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="cp"&gt;?&amp;gt;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code snippet, notice that the database is MySQL. However, if you need to change the database to MS SQL Server, the only change will be the replacement of &lt;em&gt;mysql&lt;/em&gt; with &lt;em&gt;mssql&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; PDO can handle exceptions. Therefore, always  wrap its operation in a try and catch block.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Creation
&lt;/h2&gt;

&lt;p&gt;To create a table, I will first declare a query string and then &lt;em&gt;execute&lt;/em&gt; it with exec function. Note that this will not return any data.&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;?php&lt;/span&gt;
&lt;span class="k"&gt;include_once&lt;/span&gt; &lt;span class="s1"&gt;'connection.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="nv"&gt;$db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$database&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;openConnection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

                &lt;span class="c1"&gt;// sql to create table&lt;/span&gt;
                &lt;span class="nv"&gt;$sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"CREATE TABLE `Student` ( `ID` INT NOT NULL AUTO_INCREMENT , `name`VARCHAR(40) NOT NULL , `last_ame` VARCHAR(40) NOT NULL , `email` VARCHAR(40)NOT NULL , PRIMARY KEY (`ID`)) "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

                &lt;span class="c1"&gt;// use exec() because no results are returned&lt;/span&gt;
                &lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sql&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Table Student created successfully"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

                &lt;span class="nv"&gt;$database&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;closeConnection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDOException&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"There is some problem in connection: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Data Insertion
&lt;/h2&gt;

&lt;p&gt;To insert data into a table using PDO, I will first use prepared statements to protect the query from SQL injections. Next, I will execute this query with the &lt;em&gt;execute&lt;/em&gt; function.&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;?php&lt;/span&gt;
&lt;span class="k"&gt;include_once&lt;/span&gt; &lt;span class="s1"&gt;'connection.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="nv"&gt;$db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$database&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;openConnection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

                &lt;span class="c1"&gt;// inserting data into create table using prepare statement to prevent from sql injections&lt;/span&gt;
                &lt;span class="nv"&gt;$stm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"INSERT INTO student (ID,name,last_name,email) VALUES ( :id, :name, :lastname, :email)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// inserting a record&lt;/span&gt;
    &lt;span class="nv"&gt;$stm&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;array&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="mi"&gt;0&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;'Saquib'&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;':lastname'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Rizwan'&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;'saquib.rizwan@cloudways.com'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"New record created successfully"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDOException&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"There is some problem in connection: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Select Data
&lt;/h2&gt;

&lt;p&gt;In order to select data, first create a query string and then execute it in a &lt;em&gt;foreach&lt;/em&gt; loop to fetch records from the table:&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;?php&lt;/span&gt;
&lt;span class="k"&gt;include_once&lt;/span&gt; &lt;span class="s1"&gt;'connection.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="nv"&gt;$db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$database&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;openConnection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="nv"&gt;$sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"SELECT * FROM student "&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sql&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;" ID: "&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ID'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;br&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;" Name: "&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;br&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;" Last Name: "&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'last_name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;br&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;" Email: "&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;br&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDOException&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"There is some problem in connection: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Update Data With PDO
&lt;/h2&gt;

&lt;p&gt;In order to update a record in the table, first, declare a query string, and then execute it with &lt;em&gt;exec&lt;/em&gt; function.&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;?php&lt;/span&gt;
&lt;span class="k"&gt;include_once&lt;/span&gt; &lt;span class="s1"&gt;'connection.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="nv"&gt;$db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$database&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;openConnection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="nv"&gt;$sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"UPDATE `student` SET `name`= 'yourname' , `last_name` = 'your lastname' , `email` = 'your email' WHERE `id` = 8"&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$affectedrows&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sql&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="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$affectedrows&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Record has been 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;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDOException&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"There is some problem in connection: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Delete Data With PDO
&lt;/h2&gt;

&lt;p&gt;In order to delete a record from the table, first declare a query string and then execute it with &lt;em&gt;exec&lt;/em&gt; function.&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;?php&lt;/span&gt;
&lt;span class="k"&gt;include_once&lt;/span&gt; &lt;span class="s1"&gt;'connection.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nv"&gt;$database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="nv"&gt;$db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$database&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;openConnection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                &lt;span class="nv"&gt;$sql&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"DELETE FROM student WHERE `id` = 8"&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="nv"&gt;$affectedrows&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$db&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sql&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="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$affectedrows&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Record has been successfully deleted"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;       
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDOException&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"There is some problem in connection: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;PDO is the data access layer that greatly streamlines the process of connecting and working with databases. Using PDO, you could easily carry out all database related operations without dealing with the nitty-gritty of database level problems. If you have questions or would like to add to the discussion, do leave a comment below&lt;/p&gt;

</description>
      <category>pdo</category>
      <category>php</category>
      <category>howto</category>
    </item>
  </channel>
</rss>
