Category Archives: Laravel

Laravel Tutorials

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 –

Laravel 8 Generate Unique Slug URL Example Tutorial

In this Laravel 8 Generate Unique Slug URL Example Tutorial I will show you how to generate multiple unique slug URLs in the Laravel 8 application. In this tutorial you will learn to generate unique seo friendly slug URLs in the Laravel 8 application and store slugs in the database using the id. In this example I will demonstrate you to generate unique slug or seo friendly slug url for post in laravel 8.

Laravel 8 Generate Unique Slug URL Example Tutorial

In this step by step tutorial I will demonstrate you how to Generate unique Slug URL in laravel. Please follow the instruction given below:

  • Step 1: Download New Laravel Project
  • Step 2: Update Database Details
  • Step 3: Create Migration and Model
  • Step 4: Create Controller File
  • Step 5: Register New Route
  • Step 6: View App in Browser

Download New Laravel Project

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

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

Create Migration and Model

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

Now open app/Models/Blog.php file, and define the values that you want to add in database table.

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

Create Controller File

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 New 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

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 Spatie Database Backup Tutorial

In this Laravel 8 Spatie Database Backup Tutorial, I’ll show you how to take database backup using spatie laravel backup package in laravel. In this tutorial you will learn to take Automatic Database Backup using spatie in laravel. In this article I will guide you through process how to take daily automatic database backup of your laravel application. In this example we will be using spatie/laravel-backup package to take database backup of laravel application.

Laravel 8 Spatie Database Backup Tutorial

In this step by step tutorial I will show you how to take automatic database backup of laravel application using Spatie. Please follow the instruction given below:

  • Step 1: Download Laravel Project
  • Step 2: Connect to Database
  • Step 3: Add Spatie Library
  • Step 3: Add Backup Email
  • Step 4: Update Backup Service Provider
  • Step 5: Configure Backup in Laravel
  • Step 6: Clear Config Cache
  • Step 7: Run Backup with PHP Artisan

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:

Add Backup Email

Now add your email id for database backup:

Update Backup Service Provider

Go to config/app.php file add the BackupServiceProvider class as shown.

Configure Backup in Laravel

Now,configure the laravel backup through the config/laravel-blog.php file.

it is  mandatory  setup you have to do to run the backup in laravel.

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 Add Exists Validation in Laravel 8 Input Field

In this How to Add Exists Validation in Laravel 8 Input Field tutorial, we will learn how to add already exists validation in the laravel form. In this tutorial you will learn to use already exists validation rules in laravel form input field. In this article I will share example to use already exists validation rules in laravel form. We will implement server side validation for already exists validation rules in laravel. Suppose if you want to check the student name already exists in database table before you want to save it in database. In this case we can use exists validation rule to check if student with given name is already exists in database.

How to Add Exists Validation in Laravel 8 Input Field

In this step by step tutorial I will demonstrate you with example how to add and use exists validation rules in laravel forms. Please follow the instruction given below:

  • Step 1: Create Laravel Project
  • Step 2: Add Database Credentials
  • Step 3: Build Model and Migration
  • Step 4: Run Database Migration
  • Step 5: Create Controller File
  • Step 6: Register New Routes
  • Step 7: Create Blade View File
  • Step 8: Test Laravel App

Create Laravel Project

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

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.

Build Model and Migration

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

Now, open app/Student.php model file and put the following code in it:

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

Run Database Migration

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

Create Controller File

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

Now, add the code in the app/Http/Controller/StudentController.php.

Register New 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 File

In this step we will create a blade view file, open the resources/views/welcome.blade.php file and put the following code in it:

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 –

Expo React Native Retrieve Data from Firebase Tutorial

In this Expo React Native Retrieve Data from Firebase Tutorial I will show you how to fetch data from firebase/firestore data collection in react native application. In this tutorial you will learn to Retrieve data from firebase/firestore in react native application. In this article I will share example to get data from firebase data collection in react native application.

Expo React Native Retrieve Data from Firebase Tutorial

In this step by step tutorial I will demonstrate you with example on how to retrieve data from firebase in react native application. Please follow the instruction given below:

  • Step 1: Install Expo CLI
  • Step 2: Create Expo React Native App
  • Step 3: Create Firebase Project
  • Step 4: Set Up Firebase in React Native
  • Step 5: Install React Native Elements Package
  • Step 6: Fetch Data
  • Step 7: Add Component in App Js
  • Step 8: Run App on Device

Install Expo CLI

Before staring with this tutorial you must have installed Node 12 LTS or greater version. Now, use npm or yarn to begin installing the Expo CLI.

Create Expo React Native App

Now, run the following command to download and install new React Native application.

let’s switch into the newly created project directory using following command:

Create Firebase Project

Go to firebase.google.com site, create a new firebase project for react native. Creating Firebase account from Firebase dashboard. Click on “Create a project” button and create a brand new Firebase project. We will require firebase configuration details to make the connection between react native and Firebase database.

Set Up Firebase in React Native

In this step you need to install a firebase expo package to be installed in your react native app.

Expos app requires the dotenv package to installed, so use the following command to install the package.

Lets create a .env file at the root of your react native app. Now, put the firebase credentials in it as following:

Now rename your app.json file to app.config.js and put the following code in it:

Now we will create a config directory, within this we will create a firebase.js file and put the following code in it:

Now go to Firebase database and click on the Firestore Database. Here, you need to create a students collection and add some data with name and designation properties.

Install React Native Elements Package

In this step, use the following command to install the react native elements package.

Fetch Data

In this step, we will fetch data from the firestore database and display firebase data in react native app. Lets create a components/ directory, inside this folder create fetchlist_screen.js file and put the following code in it:

Add Component in App Js

In this step we will move to the App.js file and register the newly created component in it.

Run App on Device

Now, we are ready to check the app on the smartphone. You must have installed the Expo Client on your smartphone. Download the expo from Google Play Store or App Store.

Now, you need to scan the QR code on your browser or console screen using the expo app. Your development machine and smartphone must be on same network.

React Native Login and Sign Up with Firebase Auth Tutorial

In this React Native Login and Sign Up with Firebase Auth Tutorial I will show you how to create custom react native login and sign up with firebase auth. In this tutorial you learn to create login and registration functionality in react native with firebase authentication. In this article I will share example to create registration and login in react native using firebase authentication.

React Native Login and Sign Up with Firebase Auth Tutorial

In this step by step tutorial I will demonstrate you with example how to create react native Login and Sign Up with Firebase Auth . Please follow the instruction given below:

  1. Prerequisite
  2. Install React Native Project
  3. Firebase Account Setup
  4. Set up Firebase in React Native
  5. Initiate Navigation in React Native
  6. Register with Email and Password
  7. Login User with email and password
  8. Logout from Firebase via React Native
  9. Conclusion

Prerequisite

Install React Native Project

In this step we will install fresh react native project using following command:

Install React Native app using following command.

Now, go to Y to install expo tool and run command to switch into the project directory.

Firebase Account Setup

Creating Firebase account from Firebase dashboard. Click on “Create a project” button and create a brand new Firebase authentication project. We will require firebase configuration details to make the connection between react native and Firebase database. Click on “Authentication” the users tab will contain the list of users we will create via react native’s front-end.

Set up Firebase in React Native

Now we have to install firebase in our react native application using following command

after that, run this command to create a database folder and firebase.js file.

Initiate Navigation in React Native

Next, include the following code in the App.js file.

Register with Email and Password

Put the following code in the components/signup.js file.

Login User with email and password

Put the following code in the login.js file.

Logout from Firebase via React Native

Put the following code in the dashboard.js file.

We can access the firebase.auth().signOut() method to logout from the app, after successful logout we will be redirect the user to the login screen.

Laravel 8 IPv6 Validation Integration Tutorial Example

In this Laravel 8 IPv6 Validation Integration Tutorial Example tutorial, we will learn how to add IPv6 validation in the laravel form input field. In this tutorial you will learn to add IPv6 validation rules in laravel form input field. In this article I will share example to use IPv6 validation rules in laravel form. We will implement server side validation for IPv6 validation rules in laravel.

Laravel 8 IPv6 Validation Integration Tutorial Example

In this step by step tutorial I will demonstrate you with example how to add and use IPv6 Validation rules in laravel forms input field. Please follow the instruction given below:

  • Step 1: Download Laravel Project
  • Step 2: Create Controller
  • Step 3: Register Routes
  • Step 4: Create View
  • Step 5: Start Laravel App

Download 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 Controller

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

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

app/Http/Controllers/UserController.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 View

In this step we will create some blade view files home.blade.php file and then add code in resources/views/home.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 CRUD Application Tutorial for Beginners

In this Laravel 8 CRUD Application Tutorial for Beginners tutorial I’ll show you how to create Laravel 8 CRUD Application Tutorial for Beginners. In this tutorial you will learn to create Laravel 8 CRUD Application Tutorial for Beginners.

Laravel 8 CRUD Application Tutorial for Beginners

In this step by step tutorial I’ll demonstrate you the example to create Laravel 8 CRUD Application Tutorial for Beginners.

Install Laravel 8

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

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.

Create Migration

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

Once this command is executed you will find a migration file created under “database/migrations”. lets open migration file and put following code in it –

Now, run following command to migrate database schema.

Add Resource Route

routes/web.php

Add Controller and Model

In this step we will create controller and model file using the following artisan command:

After that you will find new file in this path “app/Http/Controllers/ProductController.php”.In controller we will have following seven methods by default as shown below.

1)index()
2)create()
3)store()
4)show()
5)edit()
6)update()
7)destroy()
put the following code in ProductController.php file.

app/Http/Controllers/ProductController.php

Now, open the model file located at “app/Models/Product.php” and put following code in it:

app/Models/Product.php

Add Blade Files

Lets create following blade files:

1) layout.blade.php

2) index.blade.php

3) create.blade.php

4) edit.blade.php

5) show.blade.php

Now, put the following code respectively.

resources/views/products/layout.blade.php

resources/views/products/index.blade.php

resources/views/products/create.blade.php

resources/views/products/edit.blade.php

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

Laravel 8 Form Validation Example

In this Laravel 8 form validation example tutorial I’ll show you how to validate form data in laravel 8 application. In this laravel form validation tutorial you will learn to validate laravel form with built in laravel validation available in laravel. In this Laravel 8 form validation tutorial I’ll share various validation implementation and use case.

Laravel comes many built-in validation rules that can be easily implemented. In this example, we have used some of following validation rules –

required:- It set input field is required.
min:- Validate minimum character length.
max:- Validate maximum character length.
email: It set input must be a valid email address.
unique: It checks for unique value against a database column.
numeric: Input value must numeric.
same:- It validates two input fields value must be same.

Laravel 8 Form Validation Example

In this step by step tutorial I’ll demonstrate you how to implement validations in laravel 8 form. 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

Configure Database 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.

Create Routes:

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

routes/web.php

Create Controller:

Next, we have to create a controller to display form and to handle form validation and submit operations. Lets Create a controller named HomeController using command given below –

Open the HomeController.php file and put the following code in it.

app/Http/Controllers/HomeController.php

Create Blade File:

Now, create form blade view file to display form and submit to database. So, Go to resources/views and create createUser.blade.php and update the following code into it:

resources/views/createUser.blade.php

Laravel 8 Multiple Image Upload Tutorial

In this Laravel 8 Multiple Image Upload Tutorial, I’ll show you how to upload multiple image in laravel 8. In this laravel 8 multiple image upload example, I’ll show you how to validate upload image into folder and then save it into database. In this tutorial before saving image into database we will show preview of the images and then save it into directory. After successfully image upload into the database and folder we will display success message on the screen.

Laravel 8 Multiple Image Upload Tutorial

In this step by step Laravel 8 Multiple Image Upload Tutorial I will demonstrate you with example to upload multiple images in laravel 8. Please follow the instruction given below:

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

Add Migration and Model

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, in this step we will create model file. Please run the following command:

app/Models/File.php

Step 3: Create Routes

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

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

app/Http/Controllers/FileController.php

Image Store in Storage Folder.

Image in Public Folder

Storing Image in S3

Step 5: Create Blade File

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

resources/views/create.blade.php

Laravel 8 Create Custom Helper Functions Tutorial

In this Laravel 8 Create Custom Helper Functions Tutorial I will show you how to create custom helper functions in laravel 8 application. In this tutorial you will learn to create custom helper file in laravel 8. With custom helper file you can define functions that you can reuse in your laravel application.

Laravel 8 Create Custom Helper Functions Tutorial

In this step by step tutorial you will learn to Create Custom Helper Functions in laravel. Please follow the instruction given below:

Step 1: Create helpers.php File

In custom helper file you can define your own functions and call anywhere in your laravel project. Go to App directory and create a new file helpers.php like this app/helpers.php.

app/helpers.php

Step 2: Add File Path In composer.json File

In this step, we will add helper file path in composer.json file. Go to root directory and open composer.json file and put the following code into the file:

composer.json

Step 3: Run Command

here we use custom helper functions like changeDateFormate() and productImagePath(), here we give you example how to use custom helper functions:

Use Custom Helper function In Route:

In this example we will using custom helper function in route:

Example:-

Output:

Use Custom Helper function In Blade File:

In this example we will be using custom helper function in blade file: