Category Archives: Blog

Blog

Laravel 7/6 jQuery Form Validation Example

In this Laravel 7/6 jQuery Form Validation Example I will show you how to apply client side form validation using jquery form validation plugin. In this tutorial you will learn to apply client side form validation using jquery form validation plugin in laravel.

Input validation is a process where we check whether the input data provided by user or client is in correct format or not. If the input data fails to satisfy the validation rules then the user is responded with an error response code and the user is requested to resubmit the form with correct information. Generally Form validation is performed at server side, but can be performed at both the server and client side.

In this simple example, I’ll show you how to implement client side validation in laravel using Jquery Form Validation plugin. In this tutorial, you will learn to validate the form data in the client side before it is submitted to server. When the form data satisfies the validation it will submitted to server for further processing.

Laravel 7/6 jQuery Form Validation Example

  • Step 1: Install Laravel Fresh Setup
  • Step 2: Setup Database
  • Step 3: Make Migration file with Model
  • Step 4: Make Route
  • Step 5: Create Controller & Methods
  • Step 6: Create Blade View
  • Step 7: Start Development Server

Step 1: Install Laravel Fresh Setup

First of all we need to create a fresh laravel project, download and install Laravel using the below command

Step 2: Setup Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Make Migration file with Model

Now, in this step we will create model and migration file. Please run the following command:

Now go to Go to app/database/create_contacts_table.php and replace the below function :

Before we run php artisan migrate command go to app/providers/AppServiceProvider.php and put the below code :

Now, in this step we will create model and migration file. Please run the following command:

Now go to app/Contact.php file and add the fillable properties like this :

Step 4: Make Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 5: Create Controller

Now, lets create a controller named ContactController using command given below –

After successfully create controller go to app/controllers/ContactController.php and put the below code :

Step 6: Create Blade view

In this step, we will create a blade file. Go to app/resources/views and create one file name contact.blade.php.

Step 7: Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Laravel 7/6 Multiple Database Connections In one application

In this Laravel 7/6 Multiple Database Connections In one application tutorial I will show you how to connect or use multiple database in single laravel project. In this tutorial you will learn to connect or use multiple database in single laravel project.

In this tutorial, we would love to share with you how to connect single or multiple databases using a laravel application. Sometimes, we need to connect multiple databases to the Laravel application.

Laravel 7/6 Multiple Database Connections In one application

  • Without .env Database Connection
  • With .env Database Connection
  • Custom Connection In Migration
  • Custom Connection In Model
  • Custom Connection In Controller
  • Custom Connection with Query Builder
  • Conclusion

Without .env Database Connection

In Laravel, there is a database configuration file is located on “config/database.php”.  From this file you can set up more than one database connection. If your app uses data from two different MySql databases, you can easily define them.

With .env Database Connection

Next, you can set the database credential in your project .env file and then update your “config/database.php” with the following code given below.

Custom Connection in Migration

Open your terminal and switch to your project directory, Now, run the following command to run our migrations for the specific database connection.

If you found any error when we execute the migrate command. So that time you can clear your config cache, we will provide the command below:

This command fixed your issue;

Custom Connection In Model

You can set the “$connection” variable in your model. So use the below code for that:

Custom Connection In Controller

You can also define the connection in your controller using the “setConnection” method.

Custom Connection with Query Builder

You can also define a connection on the query builder.

Laravel 7/6 Artisan Console Command Cheat Sheet

In this Laravel artisan commands cheat sheet tutorial I will share you the complete list of laravel artisan command. In this tutorial I will also share a complete cheat sheet of the laravel artisan command for quick reference. I will also list all laravel artisan commands.

Laravel 7/6 Artisan Console Command Cheat Sheet

In this tutorial I will also share a complete cheat sheet of the laravel artisan command for quick reference.

Check Your Laravel Application Version

Laravel Composer dump-autoload:

It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php), and this is why your migration is working after you run that command.

Laravel lists artisan commands:

Laravel Application Serve:

Interact with the Laravel Application:

Publish a package’s assets to the public directory:

Generate Application Key in Laravel:

Laravel Database migrations:

Create a new resourceful controller in Laravel:

Generate database migration along with model in Laravel:

Generate database seeder in Laravel:

Create new middleware in Laravel:

Lists active routes in Laravel Application:

Create symbolic link from public/storage to storage/app/public

Flush the Laravel Application cache:

Laravel 7/6 Middleware Example Tutorial

In this Laravel 7/6 Middleware Example Tutorial, I will show you how to create custom middleware and to use in laravel based project. In this tutorial you will learn to create and use custom middlewalre in laravel. In this article I will share example to create one custom middleware to check language in query string.

What is Middleware?

In Laravel, Middleware is a filtering mechanism that facilitates filtering of incoming HTTP request before it is routed to particular controller for further processing. Laravel framework includes several in-built middleware, including authentication and CSRF protection. All of these middleware are located in the app/Http/Middleware directory. In addition to the built-in middleware, custom middleware can also be created.

Laravel 7/6 Middleware Example Tutorial

In this step by step laravel middleware tutorial I will demonstrate you with example of active or inactive users. Now we will call middleware in routes to restrict logged user to access that routes, if he/she is blocked by admin.

Step 1: Create Middleware

In this step we will first create a custom middleware in laravel based project. So let’s open your command prompt and run following command :

Now, go to app/http/kernel.php and register your custom middleware here :

app/Http/Kernel.php

After successfully register your middleware in laravel project, go to app/http/middleware and implement your logic here :

app/Http/Middleware/CheckStatus.php

Step 2: Add Route

Now, we will add some route with middleware as following

Step 3: Add Method in Controller’

Now we will create a method to check active or inactive users.

app/Http/Controllers/HomeController.php

How to check laravel version using laravel command

In this How to check laravel version using laravel command tutorial, I will show you how to check laravel version using laravel artisan command. In this tutorial you will learn to check laravel version using laravel command.

How To Check The Laravel Version?

There are following two ways in laravel to check the version of your Laravel application.

There is two way to check laravel version:

  • Check Laravel Version Using the Command
  • Check Laravel Version in Files

Check Laravel Version Using the Command

In this method, you need to switch to project directory in command prompt as following:

Now you need to use the following artisan command to check laravel version

Check Laravel Version in Files

In this method we will check laravel version from laravel application files. Go to your project root directory. And follow the path

After open this above file in your project root directory, you can search the version inside file.

Laravel 7/6 Google ReCaptcha v2 Form Validation

In this Laravel 7/6 Google ReCaptcha v2 Form Validation tutorial I’ll show you how to integrate google v2 ReCAPTCHA with laravel 7/6 forms. In this tutorial, we will implement google v2 recaptcha with form in laravel 7/6. We will be using google v2 Recaptcha in laravel to secure laravel forms against spam.

In this tutorial, we will integrate google recaptcha v2 in laravel 7/6 application. I’ll guide you through step by step how to integrate google recaptcha v2 in a laravel 7/6 application. We will be using ‘anhskohbo/no-captcha’ package for google recaptcha integration in laravel 7/6 application. In this tutorial, we will be creating a simple form with some basic fields along with the google recaptcha.

Laravel 7/6 Google ReCaptcha v2 Form Validation

In this step by step Laravel 7/6 Google ReCAPTCHA v2 Example Tutorial I’ll guide you through the process to integrate google recaptcha v2 in laravel 7/6.

  • Step 1: Download laravel Fresh Setup
  • Step 2: Setup Database Credentials
  • Step 3: Install Google Captcha Package
  • Step 4: Get Google Captcha Secrets
  • Step 5: Create Route
  • Step 6: Generate Controller by Command
  • Step 7: Create Blade View (form)
  • Step 8: Run Development Server

Step 1: Download laravel Fresh Setup

First of all we need to create a fresh laravel project, download and install Laravel using the below command

Step 2: Setup Database Credentials

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Install Google Captcha Package

We will be using ‘anhskohbo/no-captcha’ package for google recaptcha integration in laravel 5.8 application. In this step we will be installing “anhskohbo/no-captcha” via following composer command, lets open your terminal and switch to the project directory and enter the following command –

After successfully Install Google Captcha Packages, open config/app.php file and add service provider and alias.

Step 4: Get Google Captcha Secrets

Now, we need to set Google Site Key and Secret Key in .env file. Let’s start by getting Google key & secret required to make ReCaptcha authorize with the Google servers. Visit the following link to register your site –

Let’s open .env file and add this credential as following –

.env

Step 5: Create Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 6: Generate Controller by Command

Now, lets create a controller named CaptchaController using command given below –

Now open the controller let’s go to app/Http/Controllers/CaptchaController.php. Now create some methods for showing and storing data into a database.

Step 7: Create Blade View

In this step, we will create view/blade file to render a register form with recaptcha field. Lets create a “captchaform.blade.php” file in “resources/views/” directory and put the following code in it.

resources/views/captchaform.blade.php

Step 8: Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Laravel 7/6 Pagination Tutorial with Example

In this Laravel 7/6 Pagination Tutorial with Example, I will show you how to create and use pagination in laravel application. In this tutorial you will learn to implement and use laravel in-built pagination. In this article we will demonstrate you with example how to use laravel inbuilt pagination methods with bootstrap tables. This tutorial will demonstrate you how to use laravel pagination with tables and display data with pagination.

Laravel 7/6 Pagination Tutorial with Example

In this step by step tutorial we will learn about laravel inbuilt pagination:

  • Install Fresh Laravel
  • Setup Database Credentials
  • Run Migration
  • Add Fake Data
  • Create Route, Controller & Blade View
  • Start Development Server

1. Install Fresh Laravel

First of all we need to create a fresh laravel project, download and install Laravel using the below command

2. Setup Database Credentials

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

3. Run Migration

Now, run following command to migrate database schema.

4. Add Fake Records

In this step we will add some dummy records in database using following laravel command:

After run the php artisan tinker. Use the below command. This command will add 150 fake records in your database factory(App\User::class, 150)->create();

Create Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Create Controller By Artisan Command

Now, lets create a controller named UsersController using command given below –

Now open the controller let’s go to the => app/Http/Controllers/UsersController.php. Put the below Code

Create Blade Views

Next, create users.blade.php file in resources/views/ folder and copy past following code.

6. Start Local Development Server

Now we are ready to run our example so lets start the development server using following artisan command –


Now, open the following URL in browser to see the output –

Laravel 7/6 Autocomplete using Typeahead Js

In this Laravel 7/6 Autocomplete using Typeahead Js, I will show you how to create a dynamic database driven ajax jquery autocomplete using typeahead js in Laravel. In this tutorial we will create a dynamic search dropdown autocomplete which will fetch options from database table using bootstrap typeahead js.

The Typeahead JS is a jquery plugin, it is used to create dynamic autocomplete input with several options. In this example you will learn how to implement typeahead autocomplete in laravel.

Laravel 7/6 Autocomplete using Typeahead Js

In this step by step tutorial I will demonstrate how to create a dynamic database driven ajax jquery autocomplete using typeahead js in Laravel. Please follow the instruction given below:

  • Install Laravel
  • Setup Database
  • Generate Fake Records
  • Make Routes
  • Create Controller & Methods
  • Create Blade View
  • Conclusion

Install Laravel

First of all we need to create a fresh laravel project, download and install Laravel using the below command

Setup Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Generate Fake Records

In this step we will insert dummy data into database

Now we will add fake records in our database. use the below command and add 100 fake records in database :

Make Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Create Controller

Now, lets create a controller named AutoCompleteController using command given below –

After successfully create controller go to app/controllers/AutoCompleteController.php and put the below code :

Create Blade view

In this step we need to create blade view file. Go to app/resources/views and create one file name search.blade.php . After create blade file put the below html code here with jquery ui and css library file :

Start Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Laravel 7/6 REST API With Passport Auth Tutorial

In this Laravel 7/6 REST API With Passport Auth Tutorial, i will show you how to create rest api in laravel 7/6 application with passport authentication. In this tutorial we will be using passport for api authentication. we will create register and login api with simple retrieve user details.

Laravel comes with default login authentication, but when we want to create APIs we have to use tokens instead of sessions for authenticating users, as APIs does not support session variables. After login via API, user must be assigned a token and sent back to the user which is further used for authenticating API requests. Laravel provides Passport authentication which makes it easy creating REST APIs in laravel.

Laravel 7/6 REST API With Passport Auth Tutorial

In this step by step tutorial I will demonstrate you how to create REST API With Passport authentication in laravel.

  • Step 1: Install Fresh Laravel Setup
  • Step2: Configure Database Details
  • Step 3: Install Passport Packages in Laravel
  • Step 4: Run Migration and Install Passport Auth
  • Step 5: Passport Configuration
  • Step 6: Create APIs Route
  • Step 7: Create Controller & Methods
  • Step 8: Now Test Laravel REST API in Postman

Step 1: Install Fresh Laravel Setup

First of all we need to create a fresh laravel project, download and install Laravel using the below command

Step 2: Configure Database Details

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Install Passport Package In Laravel

In this step, we need to install Laravel Passport package via the composer dependency manager. Use the following command to install passport package.

After successfully install laravel passport, register providers. Open config/app.php . and put the bellow code :

Before you run migration command, go to the app/providers/AppServiceProvider.php and put the two line of code inside a boot method :

Step 4: Run Migration and Install Passport Auth

In this step we will migrate default database schema, run following command to migrate database schema.

Now, you need to install laravel to generate passport encryption keys. This command will create the encryption keys needed to generate secure access tokens. like secret key and secret id.

Step 5: Laravel Passport Configuration

Now, go to App folder and open User.php file. Then put the following code into User.php:

now, we will Register passport routes in App/Providers/AuthServiceProvider.php, Go to App/Providers/AuthServiceProvider.php and update this line => Register Passport::routes(); inside of boot method

config/auth.php

Now, go to config/auth.php and open auth.php file. Now, Change API driver to the session to passport. Put this code ‘driver’ => ‘passport’, in API

Step 6: Create APIs Route

Now, go to routes folder and open api.php. Then update the following routes into api.php file:

Step 7: Create Controller & Methods

Now, lets create a controller named AuthController using command given below –

Now, we need to create some methods in AuthController.php. So navigate to app/http/controllers/Api folder and open AuthController.php file. Then update the following methods into your AuthController.php file:

Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Test Laravel 8 REST CRUD API with Passport Auth in Postman

Now, we will call above create crud and auth apis in postman app:

1 – Laravel Register Rest API :

Laravel 7/6 REST API With Passport Auth Tutorial

2 – Login API :

Laravel 7/6 REST API With Passport Auth Tutorial

Next Step, you will call getUser, create product, list product, edit product, and delete product APIs, In this apis need to pass the access token as headers:

Laravel 7/6 Autocomplete Search using Jquery UI

In this Laravel 7/6 Autocomplete Search using Jquery UI tutorial I will show you how to create autocomplete input or search box using jquery ui in laravel. In this tutorial you will learn to create autocomplete input box using jquery ui in laravel.

In this example we will be using autocomplete jquery ui plugin. The jquery autocomplete plugin is used to create dynamic autocomplete input with several options. In this example you will learn how to implement jquery autocomplete in laravel.

Laravel 7/6 Autocomplete Search using Jquery UI

In this article, I will show you to create a dynamic database driven ajax jquery autocomplete in Laravel. You will also learn to create a dynamic search dropdown autocomplete which will fetch options from database table using jquery autocomplete.

  • Install Laravel App
  • Setup Database
  • Generate Fake Records
  • Make Routes
  • Create Controller & Methods
  • Create Blade View
  • Conclusion

1: Install Laravel App

First of all we need to create a fresh laravel project, download and install Laravel using the below command

2: Setup Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

3: Generate Fake Records

In this step we will add some dummy data into database.

Use following command to add 100 fake records in database :

4: Make Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

5: Create Controller

Now, lets create a controller named AutoCompleteController using command given below –

Now, go to app/controllers/AutoCompleteController.php and put the below code :

6: Create Blade view

In this step we will create a blade file. Go to app/resources/views and create one file name search.blade.php .

7: Start Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

Laravel 7/6 Cron Job Scheduling

In this Laravel 7/6 Cron Job Scheduling tutorial I will show you how to schedule or create cron job in laravel. In this tutorial you will learn to create or schedule cron job in laravel.

In this tutorial we will learn about laravel custom cron job scheduling, laravel run cron job manually, sey cron job in cpanel, laravel run cron job manually, laravel scheduler every second, how to run cron job in laravel.

Laravel 7/6 Cron Job Scheduling

  • Create Command Class
  • Implement Logic
  • Register Command
  • Test in Localhost
  • Laravel Set CronJob Live Server

Step 1: Create Command Class

Next, We need to create command class run by below command in command prompt :

Step 2: Implement Logic

After run this above command, it will create a new class name TodayUsers.php in app/Console/Commands/ folder. So go to app/Console/Commands/TodayUsers.php and implement your logic here :

Step 3: Register Command

After creating your logic in TodayUsers.php file. Now we need to register command in kernel.php file with task scheduling. Open app/Console/Kernel.php/ and schedule the task.

In Kernel.php file we will schedule the task to be done, when this command excute(run). In this example we will schedule the task excute for every minute.

Step 4: Test in Localhost

Step 5: Laravel Set CronJob on live server

In Laravel More Cronjob Schedule Options are available.
->cron(‘* * * * * *’); – Run the task on a custom Cron schedule

->everyMinute(); – Run the task every minute

->everyFiveMinutes(); – Run the task every five minutes

->hourly(); – Run the task every hour

->daily(); – Run the task every day at midnight

->dailyAt(’13:00′); – Run the task every day at midnight

->twiceDaily(1, 13); – Run the task daily at 1:00 & 13:00

->weekly(); – Run the task weekly

->monthly(); -Run the task every month

->monthlyOn(4, ’15:00′) – Run the task every month on the 4th at 15:00

->quarterly(); – Run the task every quarter

->yearly(); – Run the task every year

->timezone(‘America/New_York’); – Set the timezone Addiitional schedule constraints are listed below,

->weekdays(); – Limit the task to weekdays

->sundays(); – Limit the task to Sunday

->mondays(); – Limit the task to Monday

->tuesdays(); – Limit the task to Tuesday

->wednesdays(); – Limit the task to Wednesday

->thursdays(); – Limit the task to Thursday

->fridays(); – Limit the task to Friday

->saturdays(); – Limit the task to Saturday

Laravel 7/6 Email Verification Tutorial Example

In this Laravel 7/6 Email Verification Tutorial I will show you how to implement email verification for newly registered users in laravel. In this tutorial you will learn to enable email verification for account activation in laravel.

Laravel provides built-in email verification system for newly registered user. Using this, newly registered user will get an email with an account activation link. This activation link is used for account verification. When activation link is clicked, this will make user account verified and active for the application. Once user account is activated then it will be allowed to access protected routes; which can be accessible only by verified accounts.

Laravel 7/6 Email Verification Tutorial Example

In this step by step tutorial, we’ll show you how to setup email verification system for newly registered user in laravel.

  • Install Laravel Fresh Setup
  • Setup Database and SMTP Detail
  • Create Auth Scaffolding
  • Migrate Database
  • Add Route
  • Add Middleware In Controller
  • Run Development Server
  • Conclusion

1. Install Laravel Fresh Setup

First of all we need to create a fresh laravel project, download and install Laravel using the below command

2. Setup Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Now we will setup SMTP credential in .env to send emails. We are using mailtrap SMTP credential in this example.

3. Create Auth Scaffolding

Now we need to enable authentication scaffolding in laravel.

4. Migrate Database

Now, go to app/providers/AppServiceProvider.php and put the below code :

Now, in this step we will create model and migration file. Please run the following command:

After migrating the database tables we need to add the MustVerifyEmail Contracts in App/User.php. Open the App/User.php file add the constructor like

5. Add Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

6. Add Middleware In Controller

We need to add Middleware in the controller constructor. Go to app/controllers/HomeController
and put this line $this->middleware([‘auth’, ‘verified’]); inside of constructor :

7. Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –