Laravel – Send email from any controller action

Laravel send email from any controllers. In this article, I am going to discuss the Mail API in the Laravel web framework. Laravel provides a clean, simple API over the popular SwiftMailer library with drivers for SMTP, Mailgun, sendmail etc. you are allowing to quickly get started sending mail.

The below are some easy steps to follow, and you will be able to send email in Laravel controller.

  • Install Laravel.
  • Create/Update Controller
  • Define a Controller Route.
  • SMTP configure in the .env file.
  • Create a Mailable class.
  • Create a Email Template.

Install Laravel.

Run following command to create new Laravel project.

Create/Update controller

Create new controller or update already defined method in your existing controller. Here I have create a new controller using below command.

After successfully create new controller you can update below code in your file.

Define a route to send an email.

Now create a route in your web.php file to sending email to the user which you want.

Setting up SMTP details in .env file

We will use gmail SMTP to configure the settings in the .env file.

Create a Mailable class

Open your terminal and go to project root directory and type the following command.

So, it will create a file inside App\Mail\ContactUsMail.php. Now, this class catch form submitted data, and pass data to email template.

Create a email Template file in resources/views/emails/contact-us.blade.php

Now, you need to create a blade file inside the views/emails folder where you show email content and send form in laravel controller.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please SHARE this article

Laravel Vue Js

Laravel 8.x configure Vue JS CRUD with Vue Router, Vuex, Vue-Axios

In this post I am going to showing example how to configure Vue JS CRUD with Laravel 8.x. We will create a Single Page Application(SPA) using the Laravel 8.x and Vue JS. In this post you will learn how to use vue router and v-form with vue-axios package how to work with laravel and vue js crud. I am showing example on Windows 10 with XAMPP server. More details on my previous post Install Laravel on xampp server.

First Install Composer on your computer, click here to download and install composer. Also please install git bash, click here to download and install git bash. Now we use git bash to run command.

Download the NodeJs pre-built installer for Windows, click here to download and install NodeJs on your computer.

Install Laravel 8.x in xampp directory “laravelvue”:

Go to your E:\xampp\htdocs directory, right click open git bash terminal and run command composer create-project laravel/laravel laravelvue to install Laravel.

Got to “laravelvue” directory or your project directory by command cd laravelvue.

Install Laravel UI & Auth:

Now Install Laravel UI package by command composer require laravel/ui, Once the laravel/ui package has been installed, you may install the frontend scaffolding using the ui Artisan command php artisan ui vue –auth

Now create controller with Invokable by Artisan command make:controller, That command is fired into the app/http/controllers directory, go to controllers directory and you can find a new PHP file PagesController.php

Go directory app/http/controllers and open file PagesController.php and welcome view in __invoke method.

Now we have to create resources/views/welcome.blade.php vie blade file look like following code.

Now add following route in routes/web.php

So now it’s Vue time:

Now Install NPM by command npm install && npm run dev

Now Install VUE by command npm install vue

Now install all required VUE tools and libraries by a single command:


Now Install vue-router by command npm install vue-router, or for details click here

Now Install vuex by command npm install vuex –save, or for details click here

Now Install axios and v-form for client side validation by command npm install –save axios vue-axios vform, or for details click here

Now make ready resources app js in directory resources/js/app.js

Now make routes libraries js in directory resources/js/routes.js, with related component.

Now run following command to compiled js and css resource.

Now create component files in directory resources/js/components/*.vue files, with related component.

  • AppComponent.vue
  • HeaderComponent.vue
  • FooterComponent.vue
  • LoginComponent.vue
  • RegisterComponent.vue






Now every thing setup is done. Now you are ready to check it.


Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Hope it will help you.


Laravel 8 Target class [TableSeeder] does not exist

Today I am getting this error when I am trying to refresh seed with php artisan migrate:refresh –seed command. Database Seeder class is called another seeder class with $this->call(CmsPagesSeeder::class); But geeting error Target class [CmsPagesSeeder] does not exist.

Finally I have apply follwing solution and now working fine with command php artisan migrate:refresh –seed or php artisan db:seed or php artisan db:seed –class=CmsPagesSeeder

Laravel 8 Seeders and Factories are now need to add namespace at the top of class file.



Rename directory database/seeds to database/seeders


Open composer.json file and change on autoload section.


Open Database Seeder file database/seeders/DatabaseSeeder.php and add namespace Database\Seeders; on top of page.


Open your others seeders file and add namespace Database\Seeders; to all seeders class.

Done! Now run following commands you can see now DB seeder is working fine.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE


Laravel 7.x Generate Database Seeding

Laravel: Generate Seeders

Laravel includes with a simple method of seeding your database with test data using seed classes. All seed classes are stored in the database/seeds directory. We can set any name for Seed classes, but we should follow some sensible convention, such as ProductsTableDataSeeder, etc. By default, a DatabaseSeeder class is defined for you. Using default class, you may use the call method to run other seed classes, allowing you to control the seeding order.

Creating a new module

We can creating a simple module by run the following command to create a module. Replace MODULE_NAME by your desired name.

Also we can create multiple modules in one command like below.

How to Generate Seeders?

We can generate a seeder by the Artisan command make:seeder. All of generated seeders class will be placed in the database/seeds directory:

Calling default DatabaseSeeder with Additional Seeders

Default the DatabaseSeeder class, you may use the call method to execute additional seed classes. Using the call method allows you to break up your database seeding into multiple files so that no single seeder class becomes overwhelmingly large. Enter the name of the seeder classes you want to run:

Laravel: Running Seeders

Once you have done generate your seeder, you may need to regenerate Composers autoloader using the dump-autoload command.

To seed your database now you may use the Artisan command db:seed. By default, the db:seed command runs the DatabaseSeeder class, which may be used to call other seed classes.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE


Laravel 7.x Creating Table or Database Schema Migrations

Laravel: Database Migrations

Laravel database migrations are like version control for your database, allowing you to modify and share the application’s database schema. Laravel Schema facade provides database agnostic support for creating and manipulating tables across all of Laravel’s supported database systems.

How to create a migration?

We can create database migration by using the Artisan command make:migration New migration file be placed in project database/migrations directory. And each migration file name contains with timestamp, which allows Laravel to determine the order of the migrations.

Migration File Structure and Creating Table

Laravel migration class contains two methods: up and down. The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method. To create a new database table by using Schema::create method.

Run all Migrations

Please execute the migrate Artisan command to run all of your created migrations:

Roll Back or Refresh Migrate Using Artisan Command

Artisan migrate:refresh command will roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE


Laravel – Custom contact form and send email

Laravel custom contact form and send email are another routine functionality that is a requirement of more or less every website. In this article, I am going to demonstrate how you can easily create a contact form and mail function in Laravel with email sending.

Laravel is well known PHP Framework, providing multiple solutions for a problem. This is one of the main reasons of the popularity of the PHP framework. Most popular solutions cover this framework routine functionality such as authentication, sessions, routing, send email and caching.

Creating custom contact form in Laravel

  • Configure Laravel Project
  • Install HTML and Form Package
  • Configure Project Database
  • Create Database Table Using Migrations
  • Create ContactUs Model
  • Create Page Route contact
  • Create ContactUs Controller
  • Create contact Page View
  • Sending Email Function

Configure Laravel Project

Install and configure your Laravel project by using the Composer create-project command in your terminal: composer create-project laravel/laravel laraveldemo –prefer-dist “laraveldemo” is your project directory.

Install HTML and Form Package

To create custom contact form in Laravel, I will use laravelcollective/html package for contact us Forms and HTML. Launch the SSH terminal and login to your server using the Master Credentials and go to your project root directory. Run command composer require laravelcollective/html

After successful installed HTML and Forms package laravelcollective/html, goto config/app.php file and add Autoloaded Service Provider and Class Alias.

Configure Project Database

Now configure your project database connection, Find .env file in your project root directory, Open .env and add database access credentials there.

Create Database Table Using Migration Command

Go to your SSH terminal and Run artisan make:migration create_YOUR_TABLE_NAME_table command to create the database migration for creating the Contact Us model.

Contact us migration has been created, go to database/migration/2020_04_02_180504_create_contact_us_table.php and update up method public function up() with database fields like below.

Now run the artisan migrate command to generated database table contact_us with all (id, name, email, message, created_at, updated_at) fields.

Create ContactUs Model

Go to your SSH terminal and Run make:model MODEL_NAME command to create ContactUS model.

After successfully created the ContactUS model, go to App directory and Find file app/ContactUS.php and add the following code in the file.

Create Page Route contact

Now, We will go to create the route “contact-us” (Contact Us page URL). Go to routes/web.php and add the following code to the route:

Create ContactUs Controller

After setup page the routes, I will go to create a controller to handle the requests from the routes. Go to your SSH terminal and Run make:controller CONTROLLER_NAME command to create the controller.

Go to app/Http/Controllers directory and find and Open ContactUSController.php and add the following code.

Create contact Page View

Now I am going to create contact us Page View layout of the contact form. Go to resources/views/ and create a file contactus.blade.php. Place the following code in this blade (view) file.

Form output like below picture.

Sending Email Function

Custom contact us form is now functional. On submitting the form, the data will be stored in the database. I will now make the form email send function.

Now create another blade (view) file, resources/views/email.blade.php and add the following code in email blade.

Now go to project directory, Find .env file, Open .env and add SMTP email access credentials there.

Now SMTP email the configuration is done, update app/Http/Controllers/ContactUsController.php with the following code.

Laravel custom contact us form is now ready for deployment. This module save the data in the database and send 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). Thanks.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Please LIKE and SHARE


Laravel – PHP Artisan console commands with Laravel Framework 7.3

Introduction to Artisan

Artisan is the console command line interface included with Laravel Framework. Artisan provides a number of helpful commands that can assist you while you build your Laravel application.

How to use commands?

To view list of available Artisan commands by following command.


Each command also includes a “help” screen which displays and describes the command’s available arguments and options. We can view a help screen the name of the command with help

Available Aartisan console commands with description.

Below some most common uses commands with details:


Every time when we run different commands on the Laravel application laravel framework generates automatic some cache files in bootstrap/cache folder. Those files are compiled.php and services.php. Both of them file keeps list of mostly used classes/services needed by your project configuration. This php artisan clear-compiled command removes all the files from cache folder.


To enable maintenance mode, we need to execute the down Artisan command: php artisan down Put the application into maintenance mode.


To disable maintenance mode, we need to execute the up Artisan command: php artisan up Bring the application out of maintenance mode.


Create Local Development Server by artisan serve command php artisan serve The serve command is used to run the application using the PHP development server. This command is generally used for development and testing purposes.


To generating migrations for database each table migration file name contains a timestamp which allows Laravel to determine the order of the migrations php artisan make:migration create_users_table migration file created on “database\migrations” directory. We can use the –path option when executing the make:migration command, If we would like to specify a custom output path for the generated migration.


Laravel artisan db:seed command is used to add records to a database automatically using a Seeder Illuminate\Database\Seeder class to generate or provide the records. For the db:seed defines three options: class, database and force. By default the db:seed command will use for the DatabaseSeeder class, this class is defines in the project root database/seeds/DatabaseSeeder.php file. Importance seeder commands are below.


The user auth:clear-resets command can be used to remove expired password reset tokens from the database.


Flush the application cache.
Remove an item from the cache.
Create a migration for the cache database table.
Create a cache file for faster configuration loading.
Remove the configuration cache file.
Discover and cache the application’s events and listeners.
Clear all cached events and listeners.
Generate the missing events and listeners based on regist.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with me. Please LIKE and SHARE


Laravel install in localhost XAMPP server

Laravel install in localhost XAMPP server, please execute following 7 steps.

1. Download XAMPP for Windows, Linux or OSX Installer from here:
Download XAMPP and make ready your local web server.

2. Go to localhost web root directory E:\xampp\htdocs
Create a new folder for your project like “laraveldemo”

3. Run Command Prompt for Windows
Go to project root directory E:\xampp\htdocs

4. Download and run the Composer Windows Installer from here:
Download Composer

Download Composer
Download Composer

5. Check the installation using composer -V
Output: Composer version 1.10.1 2020-03-13 20:34:27

6. If Composer is works fine, than go to install laravel using the following command.
composer create-project laravel/laravel laraveldemo
composer create-project laravel/laravel laraveldemo –prefer-dist “laraveldemo” is your project directory.

laravel composer create-project

7. After complete install and create laravel project we need to create Local Development Server by artisan command. Go to project root directory E:\xampp\htdocs\laraveldemo and run artisan command php artisan serve

php artisan serve command

Browser your laravel project using url on browser and enjoy!

Laravel demo project

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with me. Please LIKE and SHARE