Category Archives: Blog

Blog

Angular 11 Google OAuth Social Login Example Tutorial

In this Angular 11 Google OAuth Social Login Example Tutorial I will show you how to create Google social login in angular. In this tutorial you will learn to build fully functional google login using Google OAuth Client ID or Google API in angular application. In this example we will be using angularx-social-login library to implement google login in angular.

Angular 11 Google OAuth Social Login Example Tutorial

In this step by step tutorial I will demonstrate you to build Google OAuth Social Login in angular application. Please follow the instruction given below:

  • Step 1: Create Angular Project
  • Step 2: Get OAuth Client ID
  • Step 3: Install Angular Social Login Library
  • Step 4: Implement Google OAuth Signin
  • Step 5: Test Login with Google.

Create Angular Project

First of all we need to make sure to have Angular CLI installed on your system:

Now, we need to create a fresh angular project, Create the angular application using the below command

Now, switch to the project directory:


Next, we will install Bootstrap package in our project. Now run the following command to install bootstrap package:

Add the Bootstrap main CSS in the styles array as shown here:

Create Google App

In this step we will obtain the client id to create the signin with google in angular.

  • Step 1: Visti the  Google Developer Console and follow the suggested process:
  • Step 2: On the google developer console, click on the “create project” button to create auth API.
  • Step 3: On the New Project screen, you need provide the project name along with any required information. Click on the CREATE button.
  • Step 4: Now, go to the OAuth consent screen, choose the External option. This will help you choose to configure and register Google auth API for specific users.
  • Step 5: Now, you need to provide application home page url, application privacy policy link, application terms of service link, or other mandatory details.
  • Step 6: After that, a form will be appear. Please select Web application from application type options. Once you have select Web application option, then one form will appear on web page. Here you have to define Name and you have also define Authorized redirect URIs field and lastly click on Create button.
  • Step 7: Lastly, OAuth client screen will appear, from here you can get your Client ID and your client secret key.

Install Angularx Social Login Package

Now, open the console then run following command to install the angularx-social-login package.

Next you need to set the google client id inside the GoogleLoginProvider() method.

Open and add the given code in app.module.ts file:

Implement Google OAuth Signin in Angular

Open and update below code in app.component.html file:


Add the following code in app.component.ts file:

Test Angular Login with Google

Check out the demo app with following url:

Laravel 8 Grayscale Image Conversion Tutorial Example

In this Laravel 8 Grayscale Image Conversion Tutorial I will show you how to convert colour image to grayscale image in laravel application. In this tutorial you will learn to convert or change colour image to grayscale image in laravel. In this example we will be using PHP image intervention package to convert or change colour image to grayscale image.

Laravel 8 Grayscale Image Conversion Tutorial Example

In this step by step tutorial I will demonstrate you how to convert an colour image to grayscale image in laravel application. Please follow the instruction given below:

  • Step 1: Install Laravel App
  • Step 2: Add Intervention Image Library
  • Step 3: Setting Up Controller
  • Step 4: Register New Routes
  • Step 5: Build Blade View in CI
  • Step 6: Run CI Application

Install Laravel App

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

Add Intervention Image Library

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

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

config/app.php

Create Controller By Artisan Command

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

Once the above command executed, it will create a controller file FileUploadController.php in app/Http/Controllers/ directory. Open the FileUploadController.php file and put the following code in it.

app/Http/Controllers/FileUploadController.php

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 Blade Views

In this step, we will create view/blade file with basic file upload form. Lets create a blade file “profile.blade.php” in “resources/views/” directory and put the following code in it respectively.

resources/views/profile.blade.php

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 Add Inertia Js Pagination in Laravel 8 Vue

In this Laravel 8 Vue Inertia js pagination tutorial I will show you how to integrate Inertia pagination in the laravel 8. In this tutorial you will learn to  integrate pagination using inertia js and Laravel Breeze from scratch. In this step by step guide on how to add pagination in laravel application using inertia js. In this example we will be using laravel breeze with inertia js to implement pagination in laravel application.

How to Add Inertia Js Pagination in Laravel 8 Vue

In this laravel 8 inertia js pagination example I will demonstrate you how to implement pagination in laravel using inertia js.

  • Step 1: Create Laravel App
  • Step 2: Connect to Database
  • Step 2: Add Breeze Package in Laravel
  • Step 3: Set Up Controller
  • Step 4: Add Routes
  • Step 5: Create View in Laravel Vue
  • Step 6: Run Laravel Project.

Create Laravel App

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

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.

Add Breeze Package in Laravel

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

you also need to compile your assets so that your application’s CSS file is available:

Now, we will add some test data into database. Use the following command to add some test data:

Now, run the following command to generate 100 user records.

Create Controller By Artisan Command

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

Now, put the following code in app\Http\Controllers\UserDataController.php file.

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 View in Laravel Vue

In this step we will create a blade view file. Open and update the resources/js/Pages/UserView.vue file with the following code.


Now, open and add code in resources/js/components/pagination.vue file.

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 8 Algolia Scout Full Text Search Tutorial Example

In this Laravel 8 Algolia Scout Full Text Search Tutorial I will show you how to integrate full-text search in a Laravel application using the Laravel Scout algolia library. In this tutorial you will learn to implementing full-text search for your Eloquent models using Algolia Scout full text search package.

The Algolia Scout package makes it easy to implement Full Text Search in laravel application. Algolia Scout automatically indexes and sync with your eloquent model for full-text search implementation. The Algolia Scout package is a powerful eloquent package that helps you develop fast full-text search functionality combining with your existing laravel models.

Laravel 8 Algolia Scout Full Text Search Tutorial Example

In this Laravel 8 Algolia Scout Full Text Search example, we will learn how to implement quick, responsive full-text search in laravel application using Algolia Scout Full Text Search package. Please follow the instruction given below:

  • Step 1: Create New Laravel Project
  • Step 2: Update Database Details in ENV
  • Step 3: Install Laravel Scout & Algolia Packages
  • Step 4: Set Up Algolia in Laravel
  • Step 5: Set Up Model and Migration
  • Step 6: Set Up Controller
  • Step 7: Create Routes
  • Step 8: Configure Blade View
  • Step 9: Run Laravel Project

Create New Laravel Project

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

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.

Install Laravel Scout & Algolia Packages

In this step, we will install Scout & Algolia Packages via the composer dependency manager. Use the following command to install Scout & Algolia Packages.


Now, use the following command to publish the scout.phpconfiguration file to your application’s config directory:


Next, update the following line of code into the .env file.


We also need to add the algolia search client package in laravel, Run the following command to install algolia search package.

Set Up Algolia in Laravel

In this step , we need to create an account to get the API keys on the Algolia website.

Set Up Model and Migration

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

Now, go to app/Models/Product.php file and put the following code. We also need to import the scout Searchable service, and define the searchableAs() method.

Now, you need to open database/migrations/create_products_table.php file and add the following code inside the file.


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

Create Controller By Artisan Command

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

The new controller has been generated, now head over to app\Http\Controllers\TextSearchController.php and add the following code.

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 Blade View

In this step we will create the blade view file open the default welcome.blade.php file and add the following code.

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 8 Add/Remove Multiple Input Fields Dynamically with jQuery

In this Laravel Dynamically Add or Remove multiple Input Fields jQuery tutorial I’ll show you how to dynamically add or remove multiple input field in form using jQuery in laravel 8. In this tutorial you will learn to dynamically add or remove multiple input field in form using jquery in laravel 8. In this tutorial I’ll share example to demonstrate Dynamically Add or Remove multiple Input Fields jQuery.

Laravel 8 Add/Remove Multiple Input Fields Dynamically with jQuery

In this step by step tutorial we will learn to dynamically add or remove multiple input field in form using jQuery in laravel 8. Please follow the instruction given below:

  • Step 1: Create Laravel 8 Project
  • Step 2: Add Database Details in ENV
  • Step 3: Set Up Model and Migration
  • Step 4: Generate and Configure Controller
  • Step 5: Create Routes
  • Step 6: Prepare Blade View
  • Step 7: Start and Test Laravel Application

Create Laravel 8 Project

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

Add Database Details in ENV

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.

Set Up Model and Migration

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

In this step, you have to register the subject property inside the fillable array within the app/Models/Student.php file.


open database/migrations/create_students_table.php file and update the new value inside the up() method.


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

Generate and Configure Controller

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

Now you need to add the following code in app\Http\Controllers\StudentController.php this file and then save the file.

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 Blade Views

Open resources/views/welcome.blade.php file, and add the following code within the file.

Start and Test Laravel Application

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 Integrate and Use Bootstrap Datepicker in Laravel 8

In this How to Integrate and Use Bootstrap Datepicker in Laravel 8 tutorial, I will show you how to use bootstrap datetimepicker in laravel blade view files. In this tutorial you will learn to integrate bootstrap datetimepicker laravel. When we create a form with different input fields, we may need dates field , time field, and datetime fields. For this we can use datetimepicker in laravel blade view files.

In this simple example, I’ll show you how to integrate bootstrap datetimepicker in laravel. We will be using bootstrap and Jquery datepicker plugin. In this tutorial, you will learn to integrate bootstrap jquery Datepicker and  datetimepicker in laravel.

How to Integrate and Use Bootstrap Datepicker in Laravel 8

In this step by step tutorial I will demonstrate you how to integrate in bootstrap datetimepicker in laravel blade view files. Please follow the instruction:

Create Laravel Project

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

Create Calendar View File

In this step, we will create view/blade file with bootstratp datepicker integration. Lets create a blade file in “resources/views/” directory and put the following code in it respectively.

Create Bootstrap Date Time Picker

Update resources/views/calendar.blade.php file:

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 8 Livewire JetStream CRUD Operations Tutorial

In this Laravel 8 Livewire JetStream CRUD Operations Tutorial I will show you how to create simple crud application using JetStream with livewire package in laravel. In this tutorial you will learn to create basic CRUD application using JetStream with 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 8 Livewire JetStream CRUD Operations Tutorial

In this step by step guide, we will be creating a simple student crud operation application with validation using JetStream with livewire package in laravel 8. In this example you will learn how to insert, read, update and delete data from database using JetStream with livewire package in laravel 8.

  • Step 1: Set Up Laravel Project
  • Step 2: Add Database Details in ENV
  • Step 3: Create Model and Migration
  • Step 4: Install Livewire and Jetstream
  • Step 5: Create CRUD Components
  • Step 6: Frame Up CRUD Component
  • Step 7: Create Routes
  • Step 8: Prepare Blade View
  • Step 9: Start Development Server

Create Laravel Project

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

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.

Create Model and Migration

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

You need to add the $fillable array and add the table values such as name, email and mobile in the app/Models/Student.php file.

We also need to configure the migration table for students, so add the table properties in the database/migrations/create_students_table.php file.

Install Livewire and Jetstream

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

Now use the npm commands simultaneously to get done the build compilation task.


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

Create Livewire CRUD Components

Now in this step we will create a livewire crud component using following laravel artisan command:

The above command will generate two files, one in Http and another in resources directories.

Update CRUD Component

Now you need to define the crud methods inside the livewire crud component file; open and update the given code in the app/Http/Livewire/Crud.phpfile.

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


If you are getting a “Route [dashboard] not defined.” error, open the resources/views/navigation-menu.blade.php file and comment entire code available in the file.

Create Blade View

Now open resources/views/livewire/crud.blade.php file.


Now create new file name it create.blade.php file inside the resources/views/livewire/ then put the following code in the resources/views/livewire/create.blade.php 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 –

How to Create Custom Auth Login and Registration in Laravel 8

In this How to Create Custom Auth Login and Registration in Laravel 8 Tutorial I will show you how to create custom login and registration system in laravel 8. In this tutorial you will learn to create custom login and registration system in laravel. Though laravel comes with default authentication system we can also create custom login, registration and logout functionality. In the step by step custom authentication tutorial I will show you to create controller, routes, model, and blade views files for custom login, registration and logout functionality.

How to Create Custom Auth Login and Registration in Laravel 8

  • Step 1: Create Laravel App
  • Step 2: Connect to Database
  • Step 3: Set Up Auth Controller
  • Step 4: Create Auth Routes
  • Step 5: Create Auth Blade View Files
  • Step 6: Run Laravel Development Server

Create Laravel App

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

Connect 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.

Now, run following command to migrate database schema.

Create Custom Auth Controller

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

Now, open app\Http\Controllers\CustomAuthController.php file and carefully place the following code within the file.

Create Auth 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 Auth Blade View Files

Now, we need to create a auth directory under resources/views/ folder and create a new login.blade.php file within, and put the following code in resources/views/auth/login.blade.php file:


Now go to resources/views/auth folder, create a new registration.blade.php file within, now update the code as following in the resources/views/auth/registration.blade.php file:


Go to resources/views/ folder, and create a new dashboard.blade.php file, then put the following code in resources/views/dashboard.blade.php file:

Run Laravel 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 8 Sanctum Authentication CRUD REST API Tutorial

In this Laravel 8 Sanctum Authentication CRUD REST API Tutorial I will show you how to create CRUD REST API with Sanctum authentication In laravel. In this tutorial you will learn to create rest api for crud operation with Sanctum authentication In laravel 8 application. In this article I will share example to create crud rest api with sanctum authentication in laravel. I will also show you how to install sanctum auth package in laravel. After installing and configure sanctum authentication in laravel we will create simple crud operation rest api. In this article we will be creating a task management crud operation rest api with sanctum authentication in laravel.

Laravel 8 Sanctum Authentication CRUD REST API Tutorial

In this step by step tutorial I will guide you through create a fully functional restful API with sanctum authentication in Laravel 8. We will be creating fully functional REST API along with sanctum Authentication. Please follow the instruction given below:

  • Step 1: Download Laravel App.
  • Step 2: Update Database Credentials.
  • Step 3: Add Laravel Sanctum.
  • Step 4: Add Table in Database.
  • Step 5: Make Laravel API Resources.
  • Step 6: Build Auth Controllers.
  • Step 7: Register New Routes.
  • Step 8: Test Laravel Auth APIs.

Download Laravel App

Update Database Credentials

Add Laravel Sanctum Library in Laravel

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

Now, we need to publish the Sanctum configuration and migration files using the Artisan command.


Now, add sanctum’s middleware to your api middleware group within your application’s app/Http/Kernel.php file:

Now, run following command to migrate database schema along with sanctum tables in our database.


Lets Import the sanctum HasApiTokens service within the app/Models/User.php. Open App/User.php model file and add ‘Laravel\Sanctum\HasApiTokens’ trait in it.

Add Table in Database

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

After that provided command, place the suggested values into the app/Models/Task.php file.

Once above command is executed there will be a migration file created inside database/migrations/ directory, just open create_tasks_table.php migration file and update the function up() method as following:

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

Build API Resources

In this step we will create Task resource api using following command:

Now, go to app/Http/Resources/Task.php and replace with the provided code.

Build Auth Controller

In this step we will create some controller files as following:

app/Http/Controllers/API/BaseController.php
app/Http/Controllers/API/TaskController.php
app/Http/Controllers/API/AuthController.php

Now put the following code in app/Http/Controllers/API/BaseController.php.

Update app/Http/Controllers/API/TaskController.php as following:

Now put the following code in app/Http/Controllers/API/AuthController.php file.

Register New Routes

After this, we need to define authentication as well as crud routes for task management in “routes/api.php” file. Lets open “routes/api.php” file and add the following routes in it.

routes/api.php

Test Laravel Auth APIs

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

1) Register API: Verb:POST, URL:http://localhost:8000/api/register

2) Login API: Verb:POST, URL:http://localhost:8000/api/login.

Now, we can test the CRUD APIs, but before that, click to “Authorization” tab, select “Bearer Token” and define the token which you received after logging-in in the previous step.

3) Task List API: Verb:POST, URL:http://localhost:8000/api/tasks

4) Task Create API: Verb:POST, URL:http://localhost:8000/api/tasks

5) Task Show API: Verb:GET, URL:http://localhost:8000/api/tasks/{id}

How to Store Backup on Dropbox in Laravel 8 with Spatie

In this How to Store Backup on Dropbox in Laravel 8 with Spatie Tutorial, I’ll show you how to take complete laravel application backup on DropBox using spatie laravel backup package. In this tutorial you will learn to store laravel site backup on dropbox using spatie in laravel. In this article I will guide you through process how to take daily automatic backup of your laravel application and store on dropbox using spatie laravel backup package. In this example we will be using spatie/laravel-backup package to take backup of complete laravel application. In this example I will also show you how to integrate DropBox in laravel 8 to store backup on DropBox.

How to Store Backup on Dropbox in Laravel 8 with Spatie

In this step by step tutorial I will demonstrate you how to integrate DropBox in laravel 8 to store backup using spatie. Please follow the instruction given below:

  • Step 1: Download Laravel Project
  • Step 2: Update Database Credentials
  • Step 3: Add Spatie Package in Laravel
  • Step 4: Configure Spatie Package
  • Step 5: Create Dropbox Token
  • Step 6: Set Up Dropbox File System
  • Step 7: Insert Dropbox Keys
  • Step 8: Store Backup on Dropbox

Install Laravel 8

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

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.

Install spatie/laravel-backup

In this step run the following command to install spatie/laravel-backup package in laravel 8:

Configure Spatie Package

Now configure your email id for backup:

Now we have to publish the backup.php file using the php artisan vendor command.


After executing the command, goto the newly generated config/backup.php and look for the destination array; and change the disks property to dropbox.

Create Dropbox Token

Create a dropbox project and get the access token.

Set Up Dropbox File System

Now, you need to run the following command to install a Filesystem adapter for DropBox:

Create a separate DropboxServiceProvider provider using following artisan command:


Now, go to config/app.php, and define the DropboxDriveServiceProvider class as following:


Now go to app/Providers/DropboxServiceProvider.php and update the following code into the file below.

Insert Dropbox Keys in Laravel

Go to config/filesystem.php file, define dropbox key, secret and authorization token within the disks and dropbox props.

Open .env file and define the dropbox auth token to make the laravel dropbox backup module work.

Clear Config Cache

Run Backup Command

In this step we are ready to take backup run the following command to check the backup file is created or not:

How to Create Custom PHP Artisan Command in Laravel 8

In this How to Create Custom PHP Artisan Command in Laravel 8 tutorial I will show you how to create a laravel custom artisan command in the Laravel 8. In this tutorial you will learn to create and use custom laravel artisan command. In this article I will share example to create a custom artisan command to generate the test data or user records and insert them into the database. Laravel provide a predefined set of artisan commands. But it also allows you to create custom artisan command.

In this step by step tutorial I will demonstrate you with example to create a custom artisan command in laravel. You will also learn to use custom artisan command in laravel. Please follow the instruction given below:

  • Step 1: Download New Laravel App
  • Step 2: Connect Laravel to Database
  • Step 3: Generate Artisan Command
  • Step 4: Create Artisan Command
  • Step 5: Run Artisan Command

Download New Laravel App

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

Connect Laravel 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.

Now, run following command to migrate database schema.

Generate Artisan Command

In this step we will generate custom artisan command using following artisan command.

Create New Laravel Artisan Command

Now, we need to update app/Console/Commands/generateUserData.php file with the following code.

Run Custom Artisan Command

Now, we are ready to use the custom artisan command we created above. We can use the custom artisan command as following:

Laravel 8 Image Upload with Spatie Media Library Tutorial

In this Laravel 8 Image Upload with Spatie Media Library Tutorial, I’ll show you how to upload image with Spatie Media Library in laravel 8. In this laravel image upload tutorial you will learn to upload image into folder and then save it into database. In this article I will share example to upload image using Spatie Media Library in laravel 8. In this example we will be using Spatie Media Library to upload image in laravel application. Before saving image into database we will show preview of the images and then save it into directory. Before uploading the image we will display preview of the image. After successfully image upload into the database and folder we will display success message on the screen.

Laravel 8 Image Upload with Spatie Media Library Tutorial

In this step by step tutorial you will learn how to Upload image with Spatie Media Library Tutorial. Please follow the instruction given below:

  • Step 1: Create New Laravel Project.
  • Step 2: Database Connection.
  • Step 3: Define App Url.
  • Step 4: Add Spatie Medialibrary Package.
  • Step 5: Create Model and Migration.
  • Step 6: Formulate New Controller.
  • Step 7: Register Routes.
  • Step 8: Create Blade View Template.
  • Step 9: Evoke Development Server.

Create New Laravel Project

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

Database Connection

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.

Add Spatie Media library Package

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

Now run the vendor publish command:

Create Model and Migration

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

Once above command is executed there will be a migration file created inside database/migrations/ directory, just open migration file and update the function up() method as following:

Open app/Models/Blog.php insert the table value and add the Spatie media library modules.

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

Create New Controller

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

Once the above command executed, it will create a controller file BlogController.php in app/Http/Controllers/ directory. Open the BlogController.php file and put the following code in it.

app/Http/Controllers/BlogController.php

Register 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 Blade View Template

Now, create and update app/resources/views/index.blade.php file.

Afetr that , create and insert the code in the app/resources/views/media.blade.php file.

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 –