Category Archives: Laravel

Laravel Tutorials

Laravel 8 Install Bootstrap Example Tutorial

In this Laravel 8 Install Bootstrap Example Tutorial I will show you how to install bootstrap 4 in laravel 8. I will also show you how to install bootstrap auth scaffolding in laravel. In this tutorial you will learn to integrate bootstrap 4 and auth scaffolding in laravel 8. In this article I will share example to install and use bootstrap 4 in laravel.

Laravel 8 Install Bootstrap Example Tutorial

In this step by step laravel 8 install bootstrap 4 tutorial. I will demonstrate you to install bootstrap 4 in laravel 8. Please follow the instruction given below:

Install Laravel/UI

Now, switch the laravel project directory and run the following composer command to install laravel/ui package. Laravel UI is an official library that offers selective or predefined UI components. The laravel/ui package comes with the login and registration scaffolding for React, Vue, jQuery, and Bootstrap layouts.

Run the following composer command to install Laravel/UI.

Install Bootstrap 4 In laravel 8

Run following artisan command to install Bootstrap in your Laravel project.

Install Bootstrap Auth Scaffolding

Use the following artisan command to Install the auth scaffoldings with Bootstrap.

Now, you have successfully installed bootstrap in your laravel 8 project, you can see your resource directory js folder.

Install Bootstrap Packages

Now, you need to install the bootstrap package and the related frontend dependencies such as jquery from npm using the following command:

Run NPM

Now, run the below command for asset compilation.

The above command compiles CSS and JavaScript files from resources/js and resources/sass folder to the public folder.

How to use Bootstrap in Laravel Blade Template

Now, you can use the bootstrap js and CSS in laravel blade template as following:

Laravel 8 Install Vue JS Example Tutorial

In this Laravel 8 Install Vue JS Example Tutorial I will show you how to install vue js in laravel 8 application. In this tutorial you will learn to integrate vue js and vue js auth in laravel 8 application. In this article I will share example on how to install vue js in laravel 8 application. We will implement a laravel 8 vue js example application. In this tutorial we will understand how to install and setup laravel 8 with vue js. In this example we will also install vue js with laravel and also laravel 8 vue auth using laravel ui.

Install Laravel 8

First, open Terminal and run the following command to create a fresh Laravel project:

Install Laravel UI

Install Laravel UI package for starting with Laravel 8 with Vue JS. So if you want to start with Laravel 8 with Vue, run the below command:

Install Vue

Install Vue with Auth

now, you need to install npm and run it. so let’s run bellow command:

Install Required Packages

I assume that you already have the Node and NPM installed on your development machine. If not, then use the following instruction:

To Install NPM, Run the following command:

Now run NPM, use the following command:

Laravel 8 Install React Example Tutorial

In this Laravel 8 Install React Example Tutorial I will show you how to install react with react auth in laravel application. In this tutorial you will learn to integrate react ui and react auth in laravel 8 application. We will implement a laravel 8 react example application. In this tutorial we will understand how to install and setup laravel 8 with react js. In this example we will also install react with laravel and also laravel 8 react auth using laravel ui.

Laravel 8 Install React Example Tutorial

In this step by step Laravel 8 Install React Example Tutorial . I will demonstrate you to install react ui and react auth in laravel 8. Please follow the instruction given below:

Install Laravel 8

First, open Terminal and run the following command to create a fresh Laravel project:

Install Laravel UI

Install Laravel UI package for starting with Laravel 8 with React JS. So if you want to start with Laravel 8 with React, run the below command:

Install React

Install React with Auth

now, you need to install npm and run it. so let’s run bellow command:

Install Required Packages

I assume that you already have the Node and NPM installed on your development machine. If not, then use the following instruction:

To Install NPM, Run the following command:

Now run NPM, use the following command:

How to Create Custom Error Page in Laravel 8

In this How to Create Custom Error Page in Laravel 8 tutorial I’ll show you how to create custom error page for 404 and 500 error in laravel. In this tutorial you will learn to create custom error page in laravel 8. In this step by step tutorial I’ll demonstrate the process to create custom 404 and 500 error page in laravel 8. You will also learn to customize default 404 and 500 error page in laravel.

How to Create Custom Error Page in Laravel 8

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:

Custom Error Pages in Laravel 8

Create 404 View File
Create 500 View File

Laravel Create Custom 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

Laravel Create Custom 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

Laravel 8 Multi Auth (Authentication) Tutorial

In this Laravel 8 Multi Auth (Authentication) Tutorial I’ll show you how to create multi auth login in laravel. In this tutorial you will learn to create multi auth login system using middleware in laravel 8. In this article I’ll share example of Multiple authentication system multiple users can log in in one application according to their roles.

When we want create separate user login or separate user/admin panel for users with different privileges or access rights in same application. With multi auth system we can allow different user to access different panel in application. In this example we will create a middleware for checking the user’s role. It is an admin or normal user. We will create middleware name admin and configuration in the kernal.php file and also in the route file.

Laravel 8 Multi Auth (Authentication) Tutorial

In this step by step tutorial you will learn about Multi Auth login in laravel. I will also demonstrate you to create laravel multi auth login using custom middleware. Please follow the instruction given below:

Step 1: Install Laravel 8

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

Step 2: 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: Update Migration and Model

Now we will add new column “is_admin” in users table and model.

database/migrations/000_create_users_table.php

app/Models/User.php

Now, run following command to migrate database schema.

Step 4: Create Auth using scaffold

Now, we will generate laravel auth scaffold to create login, register and dashboard.

Laravel 8 UI Package

Generate auth

Step 5: Create IsAdmin Middleware

app/Http/middleware/IsAdmin.php

app/Http/Kernel.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: Add Method on Controller

Now add adminHome() method for admin route in HomeController.

app/Http/Controllers/HomeController.php

Step 8: Create Blade file

In this step we will create a new blade file for admin and update for user’s blade file as well.

resources/views/home.blade.php

resources/views/adminHome.blade.php

Step 9: Update on LoginController

Now, we will change the LoginController so at the time login we redirect user according to user role. Normal user redirect to home route and for admin user redirect to admin route.app/Http/Controllers/Auth/LoginController.php

Step 10: Create Seeder

database/seeds/CreateUsersSeeder.php

Run the seeder

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

Laravel 8 Resize Image Before Upload Example

In this Laravel 8 Resize Image Before Upload Example tutorial, I’ll show you how to resize image before upload in laravel. In this tutorial you will learn to resize image before upload in laravel using Intervention Image Package. In this article I’ll demonstrate to resize and upload image in laravel Intervention Image Package. In this example will store resized image in the folder and later save it into database.

Intervention Image Package :- Intervention Image Package is an open source laravel composer package used to upload and resize images. Intervention Image package allows you to easily upload and resize image. Intervention Image package make image uploading and resizing much easier.

Laravel 8 Resize Image Before Upload Example

In this step by step guide we will be using Intervention Image Package to resize the image before uploading.

Step 1: Install Laravel 8

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

Step 2: Install Intervention Image Package

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

Step 3: 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 4: Create Controller File

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

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

app/Http/Controllers/ImageController.php

Step 5: View File and Create Upload directory

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

resources/views/resizeImage.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 use Model Events in Laravel 8

In this How to use Model Events in Laravel 8 tutorial I will show you how laravel model event works and how to use model event. In this tutorial you will learn to use model events in laravel 8 application. You will also learn about model events in laravel 8. In this article example of eloquent model events laravel 8. I will also provide you a list of laravel eloquent model events and each model event have it’s own function. In laravel each of the eloquent model events have it’s own function.

  • creating: Call Before Create Record.
  • created: Call After Created Record.
  • updating: Call Before Update Record.
  • updated: Class After Updated Record.
  • deleting: Call Before Delete Record.
  • deleted: Call After Deleted Record.
  • retrieved: Call Retrieve Data from Database.
  • saving: Call Before Creating or Updating Record.
  • saved: Call After Created or Updated Record.
  • restoring: Call Before Restore Record.
  • restored: Call After Restore Record.
  • replicating: Call on replicate Record.

How to use Model Events in Laravel 8

In this step by step tutorial I will show you how to use Model Events in Laravel 8. Please follow the instruction given below:

Create Product Model with events

First of all we will create a product model with events. Lets open create and open product model file and put the following code in it:

app/Models/Product.php

Creating and Created Event

app/Http/Controllers/ProductController.php

Please view the log file to check output

Updating and Updated Event

app/Http/Controllers/ProductController.php

Please view the log file to check output

Delete Record: Deleted Event

app/Http/Controllers/ProductController.php

Please view the log file to check output

Laravel 8 Factory Tinker Example Tutorial

In this Laravel 8 Factory Tinker Example Tutorial I will show you how to generate and insert dummy or fake records in your database table using laravel factory tinker in laravel 8 application.In this tutorial you will learn how to generate fake records in laravel using laravel factory tinker. You will also learn how to use laravel factory tinker. With Laravel factory tinker, you can generate bulk amount of records and insert into the database. In this tutorial you will also learn to use PHP Faker library in laravel to generate fake data. PHP Faker is a powerful PHP library that helps you to generate fake data for while developing new application.

In Laravel 8 we will be using “laravel/tinker” composer package to generate dummy records. Laravel 8 comes with “laravel/tinker” package. In database/factories folder you can add your different factory for different model.

Laravel 8 Factory Tinker Example Tutorial

In this step by step tutorial I will demonstrate you how to generate and insert dummy or fake records in your database table using laravel factory tinker. Please follow the instruction given below:

Install Laravel 8

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

Make sure you have composer installed.

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.

Generate Model & Run 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:

Now, go to app/Product.php and open Product model file and put the below code.

app/Models/Product.php

Create Custom Factory:

In this step you need to create a custom factory class using following artisan command:

Now open database\factories\ProductFactory.php file and put the following code in it:

database\factories\ProductFactory.php

Now, run following command in termina:

Generate Dummy Records with Factory Tinker

FInally we will be creating test data and seed them into the Product table. Use the following command:

Laravel 8 Firebase Web Push Notification Example

In this Laravel Firebase Web Push Notification Example tutorial, I’ll show you how to integrate and send web push notification using Firebase in laravel 8 application. In this tutorial you will learn integrate Firebase and send web push notification using Firebase in laravel project. In this article I will share example to integrate Firebase web push notification in laravel.

Laravel 8 Firebase Web Push Notification Example

In this step by step tutorial I will demonstrate you the process to integrate Firebase and to send web push notification in laravel. Please follow the instruction given below:

Step 1: Create Firebase Project and App

First of all you need to visit Firebase Console and create a project. then you have to create web app on that project. Then copy firebase configuration details.

Step 2: Install Laravel

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

Step 3: Create Auth using scaffold

Now, we will create auth scaffold using following command:

Laravel UI Package

Generate auth

Step 4: Create Migration and Update Model

In this step we will create migration file to add “device_token” in users table. Please run the following command:

database/migrations/2020_10_23_144523_add_column_device_token.php

app/Models/User.php

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

Step 5: Create Route

Now 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: Add Method on Controller

Now add following methods in HomeController:

app/Http/Controllers/HomeController.php

Step 7: Update Blade File

Now we have to update home.blade.php file to send notification and allow notification button.

resources/views/home.blade.php

Step 8: Create firebase-messaging-sw.js File

We have to also create firebase-messaging-sw.js in public folder and put bellow code.

public/firebase-messaging-sw.js

Run Development Server

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

Laravel 8 Fullcalendar with Create|Edit|Delete Event Example

In this Laravel 8 Fullcalendar with Create, Edit and Delete Event Example tutorial I’ll show you how to display, create, edit and delete events on the calendar using fullcalendar components in laravel 8  application. In this tutorial you will learn to display events on the calendar using fullcalendar in laravel 8. In this example, we will simply create a event crud application with fullcalender so you can easily create event, edit event and delete event. in this example we will create events table with start, edit date and title column. then you can add, edit and delete that event with database.

Laravel 8 Fullcalendar with Create, Edit and Delete Event Example tutorial

In this step by step tutorial I will demonstrate you how to show dynamic event calendar using fullcalendar in laravel 8. Please follow instruction given below:

Step 1: Install Laravel 8

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

Step 2: Create Migration and Model

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

Open migration file and update the function up() method as following:

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

Now, in this step we will create and open a model file:

app/Models/Event.php

Step 3: Create Routes

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

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

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

app/Http/Controllers/FullCalenderController.php

Step 5: Create Blade File

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

resources/views/fullcalender.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 8 Sanctum API Authentication Tutorial

In this Laravel 8 Sanctum API Authentication Tutorial I will show you how to create REST API for Simple CRUD application with Sanctum authentication In laravel. In this tutorial you will learn to create rest api for simple crud operation with Sanctum authentication In laravel 8 application. In this article I will share example to create 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 for product application.

Laravel 8 Sanctum API Authentication Tutorial

With this tutorial you learn to create fully functional restful API with sanctum authentication in Laravel 8. We will be creating fully functional REST API along with sanctum Authentication.

Step 1: Install Laravel 8

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

Make sure you have composer installed.

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 2: Use Sanctum

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

After installing package, we have to publish configuration file.

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

Now, add middleware for sanctum api.

app/Http/Kernel.php

Step 3: Sanctum Configuration

Now, we need to make following changes in our model, service provider and auth config file to complete sanctum configuration. Open App/User.php model file and add ‘Laravel\Sanctum\HasApiTokens’ trait in it.

app/Models/User.php

Step 4: Add Product Table and Model

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

Now open migration file and update the function up() method as following:

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

Lets Create “products” table and then create a model file app/Models/Product.php and put following code in it:

app/Models/Product.php

Step 5: Create API Routes

Now we will need to define crud operation rest api resource routes along with auth routes. Go to the routes directory and open api.php. Then put the following routes into api.php file:

routes/api.php

Step 6: Create Controller Files

Now, lets create following controller files:

app/Http/Controllers/API/BaseController.php

app/Http/Controllers/API/RegisterController.php

app/Http/Controllers/API/ProductController.php

Step 7: Create Eloquent API Resources

Now create new api resource using following artisan command:

app/Http/Resources/Product.php

Run Development Server

Now we are ready to test crud operation restful api and sanctum auth api in laravel. Open command prompt and run the following command to start developement server:

make sure to use token with crud api

Laravel 8 Model Observers Tutorial Example

In this Laravel 8 Model Observers Tutorial Example tutorial I will show you how model observers works and how to use model observers in larave 8. In this tutorial you will learn to use model observers in laravel 8. In this article I will help you understand how to use laravel 8 model observers.  I will also show you what is observers in laravel 8. I will also share simple example of laravel 8 model observers. We will also be creating basic example of events and observers in laravel 8.

Laravel Model Observers

When you want to listen multiple events on a given model then you can use observers to group all of your listeners into a single class. Laravel Observers are simple classes with method names that reflect the Eloquent events you wish to listen for. Each of these methods receives the model as their only argument. Laravel Observers will listen event for model like create, update and delete.

In this step by step tutorial you will understand Laravel 8 Model Observers with example.

Laravel Eloquent Hook

  • Retrieved: after a record has been retrieved.
  • Creating: before a record has been created.
  • Created: after a record has been created.
  • Updating: before a record is updated.
  • Updated: after a record has been updated.
  • Saving: before a record is saved (either created orupdated).
  • Saved: after a record has been saved (either created orupdated).
  • Deleting: before a record is deleted or soft-deleted.
  • Deleted: after a record has been deleted or soft-deleted.
  • Restoring: before a soft-deleted record is going to berestored.
  • Restored: after a soft-deleted record has been restored.

Support we have a product model with name, slug, price and unique_id column. Now when I create one record with name an price only I want to generate slug from name and auto generate unique_id. Let’s see how to Model observers class will works:

app/Models/Product.php

Now, lets create observers class for Product model using following artisan command:

app/Observers/ProductObserver.php

Now, we need to register observers class in provider.

app/Providers/EventServiceProvider.php

Create Demo Route

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 ProductController using command given below –

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

app/Http/Controllers/ProductController.php