Category Archives: Laravel

Laravel Tutorials

Laravel 8 Socialite OAuth Login with Twitter Example

In this Laravel 8 Socialite OAuth Login with Twitter Example tutorial I’ll show you how to integrate socialite Twitter social login in laravel application. In this tutorial you will learn to integrate Twitter login in laravel. In this article we will integrate login  with Twitter in laravel 8 application. This tutorial is step by step guide for you on how to integrate Twitter social login in laravel 8 using socialite package.

As we all know that users are not much interested in filling up long registration form to register with any application. Allowing users to login with their social media accounts is quick and powerful way to get registered/verified users for your laravel application. Allowing users to login with their social media accounts makes registration/login process much easier, it also encourages more users to register for your application.

Laravel 8 OAuth Login with Twitter Example

In this step by step tutorial I will demonstrate you with example how to integrate Twitter login with your laravel application. Please follow the instruction given below:

  • Step 1: Install Laravel Fresh App
  • Step 2: Setup Database
  • Step 3: Download Socialite Package
  • Step 4:Create Twitter App
  • Step 5: Add Code In Model and Migration
  • Step 6: Add Routes for Twitter App
  • Step 7: Create Controller & Methods
  • Step 8: Install Laravel Livewire and Jetstream Packages
  • Step 9: Update Login View
  • Step 10: Run Development Server

Step 1: Install Laravel Fresh App

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: Download Socialite Package

In this step we will Install Socialite Package via Composer using following command:

After Installing ‘socialite’ package, we need to add service provider and alias in config/app.php file as following.

config/app.php

In this step we will create Twitter App for Twitter social login. Use the link provided to create twitter app.

After successfully create an app in twitter and get credentials from twitter dashboard, Set client id and client secret config/service.php file :

config/service.php

Step 5: Add Code In Model and Migration

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

Next step, Go to app/database/create_users_table.php and put the below code here :

Step 6: Add Routes for Twitter App

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 7: Create Controller

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

Now, go to app/http/controllers directory and open TwitterSocialController.php file. And put the following code in TwitterSocialController.php file:

Step 8: Install Laravel Livewire and Jetstream Packages

Now, you need to run the following command to install livewire and jetstream package:

Next, install Jetstream with Livewire:

Now, you need to install and build your NPM dependencies and migrate your database:

Now, run the migration to create database table using following artisan command:

Step 9: Update Login View

Now, go to views/auth/ directory and open login.blade.php file, and update the following code into it:

Step 10: 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 Form Submit Validation Example Tutorial

In this Laravel 7/6 Form Submit Validation Tutorial I’ll show you how to submit form with validation in laravel 7 and 6. In this article I will also show you how to validate form data before submit in laravel. In this tutorial you will learn to submit form with validation in laravel.In this tutorial I will demonstrate you how to validate form data on the server-side before submit on controller and store data into database in laravel.

In this tutorial you will also learn to submit form data on the controller and validate using laravel validation rules.

Laravel 7/6 Form Submit Validation Example Tutorial

In this step by step tutorial I will share example to submit form data with validation in laravel. Please follow the instruction given below:

  • Install Laravel Fresh Setup
  • Setup Database
  • Make Migration file with Model
  • Make Route
  • Create Controller & Methods
  • Create Blade View
  • Start Development Server

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.

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 /database/migrations and open create_contacts_table.php file. Then add the below function into create_contacts_table.php file :

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 :

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

5). Create Controller

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

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

6). Create Blade view

Now, we will create a blade view file name contact.blade.php and put the following code in it:

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 where Day, Date, Month, Year, Time, Column

In this laravel eloquent query methods tutorial, I will show you how to use various laravel eloquents methods. In this tutorial you will learn about laravel eloquents methods like where, whereDate, whereRaw, whereMonth, whereYear, whereIn, whereNotIn, whereNull, whereNotNull, whereTime, havingRaw, whereBetween, whereNotBetween and laravel pluck.

Laravel where Day, Date, Month, Year, Time, Column

In this step by step tutorial I will demonstrate you use and application of laravel eloquents methods like where, whereDate, whereRaw, whereMonth, whereYear, whereIn, whereNotIn, whereNull, whereNotNull, whereTime, havingRaw, whereBetween, whereNotBetween and laravel pluck.

Laravel All Where Eloquent Queries Methods

Where() Function :

Below is simple example of laravel eloquent where() method:

orWhere() Function :

Below is simple example of laravel eloquent orWhere() method:

WhereBetween Function :

Below is simple example of laravel eloquent WhereBetween() method:

WhereNotBetween Function :

Below is simple example of laravel eloquent WhereNotBetween() method:

WhereIn() Function :

Below is simple example of laravel eloquent WhereIn() method:

WhereNull() Function :

Below is simple example of laravel eloquent WhereNull() method:

WhereNotNull() Function :

Below is simple example of laravel eloquent WhereNotNull() method:

WhereNotIn() Function :

Below is simple example of laravel eloquent WhereNotIn() method:

WhereDate() Function :

Below is simple example of laravel eloquent WhereDate() method:

WhereMonth() Function :

Below is simple example of laravel eloquent WhereMonth() method:

WhereDay() Function :

Below is simple example of laravel eloquent WhereDay() method:

WhereYear() Function :

Below is simple example of laravel eloquent WhereYear() method:

WhereTime() Function :

Below is simple example of laravel eloquent WhereTime() method:

WhereColumn() Function :

Below is simple example of laravel eloquent WhereColumn() method:

WhereRaw() Function :

Below is simple example of laravel eloquent WhereRaw() method:

OrderBy Function :

Below is simple example of laravel eloquent OrderBy() method:

SelectRaw() Function :

Below is simple example of laravel eloquent SelectRaw() method:

HavingRaw() Function :

Below is simple example of laravel eloquent HavingRaw() method:

Laravel Pluck () Function:

Below is simple example of laravel eloquent pluck() method:

Laravel Delete () Functions:

Below is simple example of laravel eloquent Delete() method:

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: