Category Archives: Laravel

Laravel Tutorials

Laravel 7 Ajax File Upload Ajax Tutorial Example

In this Laravel 7 Ajax File Upload Ajax Tutorial Example tutorial I’ll show you how to upload file with ajax in laravel. In this tutorial you will learn to upload file using ajax in laravel. In this step by step tutorial I’ll demonstrate to upload file using ajax in laravel.

Laravel 7 Ajax File Upload Ajax Tutorial Example

  • Step 1: Download Laravel New App
  • Step 2: Add Database Credentials
  • Step 3: Generate Migration & Model
  • Step 4: Create Routes For File
  • Step 5: Generate Controller by Artisan
  • Step 6: Create Blade View For File
  • Step 7: Run Development Server

Step 1: Download Laravel New App

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

Step 2: Add 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 Migration & Model

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

This command will create one model name file and as well as one migration file for the Documents table. Then Navigate to database/migrations folder and open create_documents_table.php. Then update the following code into create_documents_table.php:

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

Step 4: Create Route For File

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 Artisan

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

Note that, This command will create controller named FileController.php file.

Now app/controllers/ folder and open FileController.php. Then update the following file uploading methods into your FileController.php file:

Step 6: Create Blade View For File

In this step, create one blade view file named file.blade.php.

So navigate app/resources/views and create one file name file.blade.php. Then update the following code into your file.blade.php 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 File Upload Via API Example From Scratch

In this Laravel 7 File Upload Via API Example From Scratch tutorial I’ll show you how to create file upload api in laravel. In this tutorial you will learn to create API to upload file in laravel project.

Laravel 7 File Upload Via API Example From Scratch

  • Step 1: Install Laravel New App
  • Step 2: Add Database Credentials
  • Step 3: Generate Migration & Model
  • Step 4: Create Routes For File
  • Step 5: Generate Controller by Artisan
  • Step 6: Run Development Server
  • Step 7: Laravel Upload File Via Api Using PostMan

Step 1: Install Laravel New App

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

Step 2: Add 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 Migration & Model

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

This command will create one model name file and as well as one migration file for the Documents table. Then Navigate to database/migrations folder and open create_documents_table.php. Then update the following code into create_documents_table.php:

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

Step 4: Create Route For File

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

routes/api.php

Step 5: Generate Controller by Artisan

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

Note that, This command will create a controller named DocumentController.php file.

Now app/controllers/Api folder and open DocumentController.php. Then update the following file uploading methods into your DocumentController.php file:

If you want to upload images via api instead of files in laravel. So you can change in validation rules on the controller file, as follow:

Step 6: Run Development Server

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

Step 7: Laravel Upload File Via Api Using PostMan

Laravel 7 Ajax Crud with Image Upload Example

In this Laravel 7 Ajax 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 Ajax Crud with Image Upload Example

  • Step 1: Install Fresh laravel Setup
  • Step 2: Set database Credentials
  • Step 3: Create Migration And Model
  • Step 4: Install Yajra DataTables In App
  • Step 5: Add Route
  • Step 6: Create Controller
  • Step 7: Create Blade View
  • Step 8: Run Development Server

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

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

Navigate database/migrations/ and open create_products_table.php file. Then update the following code into this file:

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

This command will create tables in your database.

Next, Navigate to App directory and open Product.php file and then update the following code to into Product.php file as follow:

app\Product.php

Step 4: Install Yajra Datatables Package in Laravel

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

After successfully Install Yajra Datatables Packages in your laravel application. Next step, open config/app.php file and add service provider and alias

After set providers and aliases then publish vendor run by following command.

Step 5: Add 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 6: Create Controller

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

Next navigate to app/Http/Controllers and open ProductController.php file. Then update the following methods for add products, edit product and delete the product into this controller file:

In Product Controller, you need to create some methods as follow:

Index()
Store()
Edit()
Destroy()
Index() method

Store() Method

Edit() Method

Delete() Method

Now, update all methods into your ProductController.php file as follow:

Step 7: Create Blade View

Create the directory and create blade view file for CRUD operations as following: Now, Navigate to resources/views directory and create action.blade.php file.

Next, create a list.blade.php file inside resources/views/ folder and update the below code in your product list file.

Next, you will create a script code for performing create, store, update and delete products from the database table products using jQuery ajax request in laravel. So update this code in your list.blade.php file:

Next, navigate to resources/views and create image.blade.php file. Then update the following code into your image.blade.php file:

 

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 404, 500 Error Page Example

In this Laravel 7 Custom 404, 500 Error Page Example tutorial I’ll show you how to create custom 404 and 500 error page in laravel. In this tutorial you will learn to create custom error page in laravel. In this step by step tutorial I’ll demonstrate the process to create custom 404 and 500 error page in laravel.

Laravel Create Custom Error Page

In this tutorial we will be creating custom error page for 404 and 500 erro. Please Follow the instruction given below to create custom 404, 500 error pages in laravel aps:

Create 404 View File
Create 500 View File
Modify Exceptions Handler

1: Create 404 View File

In this step we will be creating custom 404 error page. Lets go to resources/views directory and create a folder named errors. Then inside the errors folder, we will create a file called 404.blade.php.

resources/views/errors/404.blade.php

2: Create 500 View File

In this step we will be creating custom 500 error page. Lets Go to resources/views directory and create a folder named errors. Then inside the errors folder, we will create a file called 500.blade.php.

resources/views/errors/500.blade.php

3: Modify Exceptions Handler

Now, navigate to app/Exceptions and open Handler.php file and find the render() method. Then modify the render() method only as follow:

as well as render 500 error page in this file as follow:

How to Check User Online or Not in Laravel 7

In this How to Check User Online or Not in Laravel 7 I’ll show you how to check User Online or Not in Laravel 7 using custom middleware. In this tutorial you will learn to check user is online or not in laravel. In this step by step guide we will be creating a custom middleware to check User Online or Not.

How to Check User Online or Not in Laravel 7

  • Step 1: Install New Laravel App
  • Step 2: Add Database Detail
  • Step 3: Generate Auth Scaffolding
  • Step 4: Add Column in User Table
  • Step 5: Create a Middleware
  • Step 6: Register Middleware in Kernel
  • Step 7: Create Controller by Artisan
  • Step 8: Check Online Status in Blade File
  • Step 9: Run Development Server

Step 1: Install New Laravel App

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

Step 2: Add 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: Generate Auth Scaffolding

In this step we will be generating laravel’s auth scaffolding using following command:

Step 4: Add Column in User Table

You need to add one column in the users table called last_seen. So, navigate database>migrations folder and open create_users_table file. Then update the last_seen column in this file as follow:

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

Step 5: Create a Middleware

In this step we will creating custom middleware using following command:

Next, navigate to app>Http>Middleware and open ActivityByUser.php middleware. Then update the following code into your middleware file:

Step 6: Register Middleware in Kernel

In this step, navigate app>Http and open Kernel.php. And register ActivityByUser.php middleware in the kernal.php file. You can see as follow:

Step 7: Create Controller by Artisan

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

Next, navigate to app>Http>Controllers and open UserController.php file. Then update the following method into your UserController.php file:

Open routes>web.php and create a route:web.php

Step 8: Check Online Status in Blade File

Navigate to resources>views and open home.blade.php. Then update the following code into home.blade.php.

Step 9: Run Development Server

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

Laravel 7 Guzzle HTTP Client Requests Example

In this Laravel 7 Guzzle HTTP Client Requests Example tutorial I’ll show you how to implement or use Guzzle HTTP Client Requests in laravel. In this tutorial you will learn to use Guzzle HTTP Client Requests in laravel.

Laravel 7 Guzzle HTTP Client Requests Example

  1. Step 1: Install Laravel New App
  2. Step 2: Add Database Details
  3. Step 3: Install guzzlehttp/guzzle Package
  4. Step 4: Create Model and Migration
  5. Step 5: Add Routes
  6. Step 6: Create Controllers By Artisan
  7. Step 7: Run Development Server

Step 1: Install Laravel New App

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

Step 2: Add 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 guzzlehttp/guzzle Package

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

Step 4: Create Modal and Migration

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

Navigate database/migrations/ and open create_posts_table.php file. Then update the following code into this file:

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

Step 5: Add 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 6: Create Controllers by Artisan

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

This command will create PostController and GuzzleController by the artisan command.

Next, Navigate to app/http/controller and open PostController.php.Then update the following methods into your controller file:

After that, Navigate to app/http/controller and open GuzzleController.php.Then update the following methods into your controller 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 –


Note that, you can also use guzzle http put and delete request in laravel apps as follow:

PUT REQUEST


DELETE REQUEST:

Laravel 7 Ajax Pagination Example Tutorial

In this Laravel 7 Ajax Pagination Example Tutorial I’ll show you how to implement ajax pagination in laravel. In this tutorial you will learn to create ajax pagination in laravel project.

Laravel 7 Ajax Pagination Example Tutorial

  1. Step 1: Install Laravel New App
  2. Step 2: Add Database Details
  3. Step 3: Create Model and Migration
  4. Step 4: Add Routes
  5. Step 5: Create Controllers By Artisan
  6. Step 6: Create Blade Views
  7. Step 7: Run Development Server

Step 1: Install Laravel New App

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

Step 2: Add 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: Create Modal and Migration

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

Navigate database/migrations/ and open create_posts_table.php file. Then update the following code into this file:

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

Step 4: Add 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: Create Controllers by Artisan

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

This command will create PostController by the artisan command.

Next, Navigate to app/http/controller and open PostController.php.Then update the following methods into your controller file:

Step 6: Create Blade Views

In this step, we will create view/blade file. So navigate to resources/views folder and create the blade view as following:

Create first file name posts.blade.php and update the following code into it:

After that, create a new blade view file that named load_posts_data.blade.php and update the following code into it:

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 Sweet Alert Example Tutorial

In this Laravel 7 Sweet Alert Example Tutorial I’ll show you how to add Sweet Alert to laravel application. In this tutorial you will learn to add or implement Sweet Alert in laravel project.

Laravel 7 Sweet Alert Example Tutorial

  1. Create Methods in Controller
  2. Add Route
  3. Use SweetAlert on Blade Views File
  4. Run Development Server

Step 1: Create Methods in Controller

Step 2: Add Route

Navigate to routes/web.php and update the following routes:

Step 3: Use SweetAlert On Blade View File

Now, Navigate to resources/views folder and create one blade view file that named users.blade.php file and update the following code into users.blade.php file:

Note that, after creating a blade view file, you need to include sweet alert libary on your blade view files:

And you can call sweet alert methods as follow:

Step 4: 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 Install Vue JS Example Tutorial

In this Laravel 7 Install Vue JS Example Tutorial I’ll show you how to install Vue Js in laravel application. In this tutorial you will learn install Vue Js in laravel project.

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: Install Laravel UI Package

In this step we will install laravel UI package using following composer command:

Step 3: Adding Vue to Laravel App

In this step we will add Vue js to laravel application

Install Vue

This command will install vue into your laravel app.

Install Vue with auth

Step 4: Installing Vue.js Dependencies

Now, Install Vue.js dependencies following command:

Install NPM

Run NPM

Note that, You have already installed node and npm in your system for the above-given npm commands.

Laravel 7 Vue JS Post Axios Request Example

In this Laravel 7 Vue JS Axios post Request Example tutorial, I’ll show you how to implement post request with Vue JS Axios in laravel. In this tutorial you will learn to create post request with Vue JS Axios in laravel.

Laravel 7 Vue JS Post Axios Request Example

  • Step 1: Download Laravel Fresh Setup
  • Step 2: Setup Database Credentials
  • Step 3: Make Migration & Model
  • Step 4: Add Routes
  • Step 5: Make Controller By Command
  • Step 6: Install Vue Js dependency
  • Step 7: Create blade file and layout
  • 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: Make Migration & Model

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

after that, open your posts migration file and paste the following code:


Again open your terminal and run the php artisan migrate to migrate our tables into your database:

After that, open Post model and update the following code into your app/Post.php model file:

Step 4: Add 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:  Make Controller By Command

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

This command will create a controller that name PostController inside the controller folder. Next, open it app/Https/Controller/PostController.php and update the following methods into your PostController file:

Step 6: Install Vue Js dependency

now open webpack.mix.js file and update the following code into your file. Make an asstes folder inside resources folder and copy js and sass folder inside it. Thats all. We need it to setup our laravel mix

Next Go to resources/assets/js/components/ folder. And create a new components name PostComponent.vue. Then update the following code into your PostComponent.vue file:

The above code is to send form data to controller using axios post request in laravel. Next, Go to resources/assets/js then open app.js file and intialize vue js components in this file. So open app.js file and update the following code into your app.js file:

Step 7: Create blade file and layout

Now, Open resources/layouts/app.blade.php and update the following code into it:

Next, resources/views/ and create a new blade view file name post.blade.php. And update the following code into your post.blade.php view file:

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 Vue JS Axios Get Request Example

In this Laravel 7 Vue JS Axios Get Request Example tutorial, I’ll show you how to implement get request with Vue JS Axios in laravel. In this tutorial you will learn to create get request with Vue JS Axios in laravel.

Laravel 7 Vue JS Axios Get Request Example

  • Step 1: Download Laravel Fresh Setup
  • Step 2: Setup Database Credentials
  • Step 3: Generate Fake Data
  • Step 4: Add Routes
  • Step 5: Make Controller By Command
  • Step 6: Install Vue Js dependency
  • Step 7: Create blade file and layout
  • 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: Generate Fake data

Now, use the following artisan command to generate dummy data:

Step 4: Add 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:  Make Controller By Command

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

Next, open it app/Https/Controller/UserController.php and update the following methods into your UserController file:

Step 6: Install Vue Js dependency

Next Go to resources/assets/js/components/ folder. And create a new components name UserComponent.vue. Then update the following code into your UserComponent.vue file:

The above code is to display users list using axios get request in laravel. Next, Go to resources/assets/js then open app.js file and intialize vue js components in this file. So open app.js file and update the following code into your app.js file:

Step 7: Create blade file and layout

Now, Open resources/layouts/app.blade.php and update the following code into it:

Next, resources/views/ and create a new blade view file name users.blade.php. And update the following code into your users.blade.php view file:

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 Vue JS Infinite Scroll Example Tutorial

In this Laravel 7 Vue JS Infinite Scroll Example Tutorial I’ll show you how to create Infinite Scroll with Vue Js in laravel. In this tutorial you learn to create or implement Infinite Scroll with Vue Js in laravel application.

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

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

This command will create post model, migration, and factory file into your project. Now, Go to app/database/migrations and find posts migration file. Then open it and update the following code into your posts migration file:

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

Step 4: Generate Dummy Data

Next step, generate fake or dummy data for posts table. So go to database/factories folder and find PostFactory.php file. After that, open and update the following code in PostFactory.php file as follow:

Next open terminal and run following command to generate dummy data for posts table:

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 Controller By Command

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

This command will create PostController inside app/Http/Controllers/ folder. Now, open your PostController and update the following methods into your PostController File:

Step 7:  Configuration Vue JS

Install npm:


Install vue-resource:


Install vue-infinite-loading:

Step 8: Update app.js And Default Components

Go to resources/assets/js/ folder and find the app.js file inside this directory. Then update the following code into your app.js file:

resources/assets/js/app.js

resources/assets/js/components/ExampleComponent.vue

Step 9:  Add Vue Components on welcome.blade.php file

Go to resources/views and find welcome.blade.php file inside this folder. Then update the following code into your welcome.blade.php file:

And also update the following code into app.blade.php file, which is located on resources/views/layouts/ folder.

Step 10: Run Development Server

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