Category Archives: Blog

Blog

Laravel 7 Crud with Image Upload From Scratch

In this Laravel 7 Crud with Image Upload Example tutorial, I’ll show you how to create basic CRUD application with Image upload in laravel. In this tutorial you learn to create simple CRUD application with image upload. In this step by step tutorial we will be creating simple crud application with image upload in laravel.

Laravel 7 Crud with Image Upload From Scratch

  • Install Laravel Fresh Setup
  • Setup Database Credentials
  • Generate Model and Migration
  • Create Resource Route & Controller
  • Create the blade view
  • 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 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: Generate Model and Migration

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

The above command will create a model name Product and a migration file for Product table. Now, go to database/migrations file and put the below here :

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

If you found any query builder error in command prompt go to => app\Providers\AppServiceProvider.php and put the below code here :

And then run this below command :

Now, add the fillable property inside Product.php file.

4). Create Resource Route & Controller

In this step we will create a resource route and controller using following command:

The above command will create a controller name ProductController with default methods like index, store, create, update, destroy, show, edit. Now we need to add the resource route. Go to routes/web.php put the below routes here :

Next open controller, Go to app/HTTP/Controller/ProductController and put the below code here :

Step 5: Create the blade view

Create the product directory with inside following blade view file for CRUD operations:

  1. Layout.blade.php
  2. List.blade.php
  3. Create.blade.php
  4. Edit.blade.php

Layout.blade.php

List.blade.php

Create.blade.php

Edit.blade.php

Step 6: 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 socialite Linkedin Login Example

In this Laravel 7/6 socialite Linkedin Login tutorial I’ll show you how to integrate socialite LinkedIn social login in laravel application. In this tutorial you will learn to integrate LinkedIn login in laravel. In this article we will integrate login  with LinkedIn in laravel application. This tutorial is step by step guide for you on how to integrate linkedin social login in laravel 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. In this step by step tutorial, you will learn to integrate linkedin login with your laravel application.

Laravel 7/6 socialite Linkedin Login Example

  • Step 1: Install Laravel App
  • Step 2: Connect App to Database
  • Step 3: Install Socialite Package
  • Step 4: Create a Linkedin App
  • Step 5: Add Code in Migration, Model File
  • Step 6 Run Migration
  • Step 7: Add Routes for Linkedin Login
  • Step 8: Create Controller
  • Step 9: Generate Bootstrap Auth File
  • Step 10: Add Linkedin Login In Blade View
  • Step 11: Run Development Server

Step 1: Install the laravel App

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

Step 2: Connect App to 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

Step 4: Create a Linkedin App

In this step, we will create linkedin app for client and secret key, go to following link

Now create linkedin app filling the details and create your linkedin app. After creating the app set the redirect URL. Now, copy the client id and secret from linkedin app dashboard. Now, go to your project config directory and open service.php file. Then add linkedin app details in service.php file as following:

Step 5: Add Code in Migration, Model File

Now, go to database/migrations directory and open create_users_table.php. Then put the following code into it:

Go to app/User.php and add fillable property like following in User.php model file:

Step 6: Run Migration

Before you run PHP artisan migrate command go to app/providers/AppServiceProvider.php and put the following code in it:

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

Step 7: Add Routes for Linkedin Login

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

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

After creating controller go to app/http/controllers directory and open LinkedinSocialController.php file. And put the following code into LinkedinSocialController.php file:

Step 9: Generate Bootstrap Auth File

Install Laravel UI

Create Auth

NPM Install

Step 10: Add Linkedin Login In Blade View

In this step, you need to add two buttons in laravel blade view for social LinkedIn login. So go to Resources/Views/Auth/register.blade.php and add a Linkedin social login button

Then, go to Resources/Views/Auth/login.blade.php and add a LinkedIn social login button:

Step 11: 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 Login Registration Logout Example

In this Laravel 7/6 login, registration, logout example tutorial I will show you how to use laravel default login registration logout in laravel application. In this tutorial you will learn to create your own laravel login, registration, forget password and reset password functionality. This tutorial is complete laravel authentication system guide that helps you to implement laravel default authentication in laravel application.

Laravel 7/6 Login Registration Logout Example

  • First Install Laravel Fresh Project
  • Configuration changes in .env file
  • Generate Laravel Application Key
  • Database Migration
  • Create a Login Authentication  Laravel
  • Run the Development Server

1. First Install Laravel Fresh Project

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

2. Configuration changes in .env file

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 Laravel Application Key

Now we will generate laravel application key using following command:

4. Database Migration

Before you run php artisan migrate command. Go to the app/providers/AppServiceProvider.php and put the following code in boot method

5. Laravel Authentication

Now, we will enable laravel default authentication using following command:

The above command will generate default authentication routes, controllers and views files for Laravel Login Authentication and registration. After that you can run following command and check ui commands info.

You can use following commands for creating auth:

Using Vue:

Using React:

Now you need to run following npm command, otherwise you will not see layout of login and register page.

Install NPM:

6. Run the Development Server

laravel authentication is successfully completed, Now Go to the browser and hit the

If you did not run PHP artisan server command, direct go to your browser and type the URL

Laravel 7 Ajax Get Data From Database

In this Laravel ajax get data from the database tutorial I will show you how to fetch data from database using ajax in laravel applications. In this tutorial you will learn to use ajax in laravel. In this article I will demonstrate you how to fetch records from database using ajax in laravel. Using ajax you can fetch data from database without reloading page in laravel. In this step by step guide you will understand laravel ajax request implementation.

Laravel 7 Ajax Get Data From Database

  • First Install New Laravel Setup
  • Configure .env file
  • Create One Model and Migration
  • Make Route
  • Generate Controller by command
  • Create Blade View
  • Start Development Server

Step 1: First Install New Laravel Setup

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

Step 2: Configure .env file

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.

Next go to app/datatabase/migrations and open users migration file and put the below code here :

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:

Step 3: 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 4: Generate Controller by Command

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

Next we will use only four methods the from resource controller. Next open your controller and replace the methods given in below :

Step 5: Create blade view :

In this step, we will create a blade file name get-ajax-data.blade.php. Now, go to resource/views/ and create a blade file and put following code in it:

Step 6: 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 –

How to Use try catch In laravel Example Tutorial

In this How to Use try catch In laravel Example TutorialI will show you How to Use try catch In laravel.In this tutorial you will learn to use try catch exception handling in laravel framework. While working or developing application with Laravel framework, you may encounter many errors. It is very important to handle these errors properly in order to build safe and error free laravel application. In laravel you can use try catch statement for proper error handling in laravel.

How to Use try catch In laravel Example Tutorial

Below is the syntax that represents the try..catch statement:


The try…catch statement is used to handle the errors.

Find Product By Title

Let’s take a look example of laravel try catch. Here you have product table and find the product with it’s title. So you have the following things:

routes/web.php

 

Controller with two methods:

Blade view files as following:

index.blade.php

search.blade.php

Get Errors

In the above example if the product is found, there is no error but if a product is not found, we will encounter some errors on your search.blade.php file.

Now, go to .env file and set

Then the browser will just show blank screen, looks like something went wrong. But that still doesn’t give any valuable information to our visitor. If the product is not found there will error occurs, so you can pass errors on your search.blade.php file using try..catch statement as following:

we can display an error message in Blade file as following

Laravel Livewire Form Tutorial

In this laravel livewire form tutorial, I’ll show you how to install and use laravel liveware package in your laravel application. In this tutorial you will learn to install, setup and use laravel livewire form. In this article I will guide you through how to submit and store form data using the laravel livewire form package in laravel.

Laravel Livewire Form Tutorial

  • Step 1: Install Laravel
  • Step 2: Add Database Detail
  • Step 3: Generate Migration and Model by Command
  • Step 4: Install Livewire
  • Step 5: Create Component
  • Step 6: Create Route
  • Step 7: Create View File
  • Step 8: Run Development Server

Step 1: Install Laravel

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

Step 2: Add Database Detail

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: Generate Model and Migration By Command

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

The above command will create a model name Contact and also create a migration file for Contact table. After successfully run the command go to database/migrations file and put the below here :

now go to app\Providers\AppServiceProvider.php and put the below code here :

Now run the following command to create the table into your database:

Next, Open App/Contact.php file and add the fillable properties:

Step 4: Install Livewire

In this step, we will install livewire Package via the composer dependency manager. Use the following command to install livewire Package.

Step 5: Create Component

In this step we will create a component using following artisan command:

You can see a created file on the following path:

Now, put the following code into your files, so follow the given path and update the code:

app/Http/Livewire/ContactForm.php

resources/views/livewire/contact-form.blade.php

Step 6: 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 7: Create View File

In this step, we will create a blade files that name form.blade.php file inside resources/views/ folder and put the following code into your file:

resources/views/form.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 Custom Validation Error Messages Example

In this laravel 7 custom validation error messages example tutorial I will show you how to implement custom validation message error in laravel projects. In this tutorial you will learn to customize default validation message and use custom validation error messages in laravel forms. In this step by step guide I will demonstrate you how to use custom validation error messages on laravel forms.

Laravel 7 Custom Validation Error Messages Example

  • Step 1: Install Laravel Application
  • Step 2: Setup Database Credentials
  • Step 3: Run Migration Command
  • Step 4: Create Route
  • Step 5: Generate Controller By Command
  • Step 6: Create the blade view
  • Step 7: Run Development Server

Step 1: Install Laravel Application

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: Run Migration Command

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

Step 4: 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

Step 5: Generate Controller By Command

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

Now, go to app/Http/Controllers/CustomErrorController.php and put the following code into your controller file:

app/Http/Controllers/CustomErrorController.php

Step 6: Create Blade View

Now, we will go to resources/views folder and create a blade view file name from.blade.php and put the following code into your file:

resources/views/form.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 –

How to Set or Increase Session Lifetime in Laravel

In this How to Set or Increase Session Lifetime in Laravel I will show you how to set or increase the session timeout or session lifetime in your laravel project. In laravel the session-timeout defines the default session timeout interval for all sessions. The session timeout is defined in minutes. In this tutorial you will learn following topics:

  • How to Set or Increase Session Lifetime in Laravel
  • What is default session time in laravel?
  • How does laravel session expire?

How to Set or Increase Session Lifetime in Laravel

In laravel if you want to set session lifetime for 1 year you can do this as following:

How to Set or Increase Session Lifetime in Laravel

Using .env File

If you set the session timeout in the .env file. The config directory has a session.php. In this file, the session timeout of your laravel web application is set in this way.

Using Config File

O open config/session.php file and set session timeout as following:

What is default session time in laravel?

The cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means “until the browser is closed.” Defaults to 0.

How does laravel session expire?

If you want laravel session to immediately expire on the browser closing then set that option. | */ ‘lifetime’ => 4320, ‘expire_on_close’ => false, if you want to set session lifetime per user, you need to set this value before logging in the user.

Laravel Logout on Session Expire

In this Laravel Logout on Session Expire tutorial I’ll show you how to logout user’s on session expires. In this tutorial, you will learn to logout user and redirect to the login page when user session timeout or expired. In laravel you can also schedule a task using cron job and artisan command to auto-logout when session expired/session timeout and redirect user’s.

Laravel Logout on Session Expire

Step 1: Create Middleware file

This command will create a middleware name SessionExpired.php. Next find app/Http/Middleware/SessionExpired.php & update the following code into your middleware file:

Step 2: Register the Middleware in Kernal file

In this step, Visit app/Http directory and open a file name Kernel.php & put the below code.

Now open your browser put the below URL:

Laravel 7 Load More Data On Infinite Page Scroll

In this Laravel 7 Load More Tutorial From Scratch tutorial I’ll show you how to implement infinity scroll or dynamix ajax load more on page scroll in laravel. In this tutorial you will learn to implement dynamic load more pagination in laravel. In this step by step guide I’ll share example of ajax load more or infinity scroll in laravel.

Laravel 7 Load More Data On Infinite Page Scroll

  • Download Laravel Fresh Setup
  • Configure .env file
  • Create One Model and Migration
  • Create Route
  • Generate Controller by Command
  • Create Blade View
  • 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: Configure .env file

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: Create Model and Migration

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

Now, go to app/database/migrations and open posts migration file and put following fields

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

Step 4: 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 5: Generate Controller by Command

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

Now, go to app/http/controller/PostController and open PostController. And put the following code into your PostController file:

Step 6: Create a blade view

Now, we will create a blade file name posts.blade.php. And update the below HTML code into your posts.blade.php file:

This blade view file displays your all blog posts when you scroll the page down. Now, update the following script into your blade view file:

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 Livewire Crud Example

In this Laravel livewire crud example tutorial I will shoe you how to create simple crud  application using livewire package in laravel. In this tutorial you will learn to create basic CRUD application using livewire package in laravel. In this article you will also learn how to validate laravel livewire forms, how to update livewire form data, and how to edit livewire form data in laravel.

Laravel 7 Livewire Crud Example

  • Step 1: Download Laravel Fresh App
  • Step 2: Setup Database Configuration
  • Step 3: Install Livewire
  • Step 4: Create Component
  • Step 5: Add Route
  • Step 6: Create Blade Views
  • Step 7: Run Development Server

Step 1: Download 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 Configuration

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 Livewire

In this step, we will install livewire Package via the composer dependency manager. Use the following command to install livewire Package.

Step 4: Create Component

In this step we will create a component using following command:

The above command will create two files on the following location:

app/Http/Livewire/Users.php

Step 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

Step 6: Create Blade Views

In this step we will create following blade views file and update the following code into your files:

resources/views/livewire/users.blade.php

resources/views/livewire/home.blade.php

resources/views/livewire/create.blade.php

resources/views/livewire/update.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 jwt Authentication Rest API Tutorial

In this Laravel 7 jwt Authentication Rest API Tutorial I’ll show you how to build the rest APIs with jwt (JSON web token) authentication in laravel 7. In this example I’ll also show you how to install jwt auth and configure jwt auth in laravel 7. In this article, we will learn to create fully functional restful API with JWT Authentication in Laravel 7. In this tutorial, we will be creating fully functional REST API along with JWT Authentication.

Laravel 7 jwt Authentication Rest API Tutorial

  • Step 1: Install Laravel 7/6/5 App
  • Step 2: Configure Database
  • Step 3: Install jwt laravel
  • Step 4: Configure jwt in laravel
  • Step 5: Generate jwt secret key
  • Step 6: Add jwt Class in Model
  • Step 7: Add Api Routes
  • Step 8: Create Api Controller
  • Step 9: Run Development Server

Step 1: Install Laravel 7/6/5 App

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

Step 2: Configure 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: Install jwt laravel

In this step, we will install tymon jwt auth package via the composer dependency manager. Use the following command to install laravel jwt authentication package.

Step 4: Configure jwt in laravel

After Installing tymon/jwt-auth package, we need to add service provider and alias in config/app.php file as following.

config/app.php

After that, run the below given command to publish the configuration file in Laravel for jwt auth:

Step 5: Generate jwt secret key

Now, you need to generate jwt encryption keys. Use the following command to generate encryption keys needed to generate secure access tokens:

Now, open JWTGenerateCommand.php file and put the following code,

vendor/tymon/src/Commands/JWTGenerateCommand.php

Step 6: Add jwt Class in Model

In this step, Navigate to App folder and open User.php file. Then update the following code into User.php:

Step 7: Add Api Routes

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

Step 8: Create Api Controller

After that, you need to create some methods in JwtAuthController.php. So go to app/http/controllers/ and open JwtAuthController.php file. Then put the following methods into your JwtAuthController.php file:

Step 9: Run Development Server

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