Category Archives: Blog

Blog

Laravel 8 Single Image File Upload With Validation

Laravel 8 Single Image File Upload With Validation

In this Laravel 8 Single Image File Upload With Validation Tutorial Example, we will learn how to upload and save single image file in laravel application database. I’ll show you how to upload file in Laravel 8 application, store all the image into the MySQL database.

In this laravel simple 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 validate image and then save it into directory using. Before uploading the image we will perform server side validation. After successfully image upload into the database and folder we will display success message on the screen.

Table of Contents

  1. Create Laravel 8 Project
  2. Database Configuration
  3. Create Model and Migrations
  4. Create Controller
  5. Create Routes
  6. Create Blade File
  7. Start Laravel Server

1). Install Laravel Fresh App

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

2). Setup 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.

3). Generate Image Migration & Model

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

After that, open create_photos_table.php file inside LaravelImage/database/migrations/ directory. And the update the function up() with following code:

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

4). Create Image Upload 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

5). Create Image Upload Controller

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

Now, go to app/http/controllers and open UploadImageController.php file. And update the following code into it:

6). Create Blade View

Now we will create a blade view file. Go to app/resources/views and create one file name image.blade.php :

7). Create Images Directory inside Storage/app/public

Now, create images directory inside storage/app/public directory.

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 –

How to Upload File in Laravel 8 with Validation

In this Laravel file Upload with validation example, we will learn how to upload and validate file before upload in laravel. In this laravel file upload example, I’ll show you how to validate and upload file into folder and then save it into database. In this tutorial before saving file into database we will validate file and then save it into directory. Before uploading the files we will perform server side validation. After successfully file upload into the database and folder we will display success message on the screen.

How to Upload File in Laravel 8 with Validation

  • Step 1 – Download Laravel 8 Application
  • Step 2 – Database Configuration
  • Step 3 – Build File Model & Migration
  • Step 4 – Create Routes
  • Step 5 – Build Upload Controller By Artisan Command
  • Step 6 – Create File Upload Form
  • Step 7 – Create Directory inside Storage/app/public
  • Step 8 – Run Development Server

Step 1 – Download Laravel 8 Application

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 – Build File Model & Migration

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

After that, open create_files_table.php file inside /database/migrations/ directory. And put the following code in it:

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

Step 4 – Create Routes

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

routes/web.php

Step 5 – Build File Upload Controller By Artisan Command

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

After that, go to app/http/controllers and open FileUploadController.php file. And put  the following code into it:

The following line of code will upload an file into the files directory:

Step 6 – Create File Upload Form

Go to resources/views and create file-upload.blade.php and update the following code into it:

The following below code will display the validation error message on the blade view file:

Step 7 – Create Directory inside Storage/app/public

Now, create directory name files inside storage/app/public directory. Because the following line of code will upload an file into the files directory, which is located inside storage/app/public/ directory:

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 –

How to Make HTTP Requests with AJAX in Laravel 8 and Bootstrap

In this Laravel 8 Ajax Post Form Data With Validation tutorial you’ll learn to validate and submit form data without reloading or refreshing of page using ajax.

In this tutorial I’ll show you step by step how to submit and validate form data without reloading or refreshing of page using ajax. Generally Form validation is performed at server side, but can be performed at both the server and client side. In this laravel form validation tutorial we will be learning about laravel server side validations. In this tutorial, I’ll show you how to define laravel validation rules, how to validate form input and to display validation errors using ajax. In Laravel, to submit form data using ajax we must have to incorporate csrf token with form data and set X-CSRF-TOKEN request header with ajax form submit request.

How to Make HTTP Requests with AJAX in Laravel 8 and Bootstrap

In this step by step tutorial you will learn to make ajax request in laravel framework. In this tutorial I will demonstrate you how to make ajax http requests in laravel. Please follow the instruction given below:

  1. Install Laravel Project
  2. Make Database Connection
  3. Model and Migration
  4. Create Controller
  5. Create Routes
  6. Create Layout
  7. Make Ajax Request
  8. Define AJAX Logic
  9. Test Laravel AJAX App
  10. Conclusion

Install 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 & Configure Model and Migration

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

Now, go to app/Models/Todo.php and place the following code

Now, open migrations/xxxx_xx_xx_xxxxxx_create_todos_table.php and place the following code.

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

Create Controller

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

Paste the following code in the newly created controller in app/Http/Controllers/CrudController.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 Layout

After creating the recommended file, also create views/layouts/app.blade.php file and folder. Add the following code inside the app.blade.php file.

Make Ajax request in Laravel

Put the following code in views/home.blade.php file.


Now, we need to create a todo.js file inside the public/js folder. Place the entire 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 –

Create Validate Laravel 8 Contact Form with Send Email

In this Create Validate Laravel 8 Contact Form with Send Email tutorial I will show you how to Create a contact form with validation in laravel. We will also send an email to admin on form submission and save contact form input in the database.

In this tutorial, you will learn to create a contact form UI using Bootstrap CSS in laravel. I will also  show you how to validate contact form, sending email to the admin with contact form values using mailtrap.

Create & Validate Laravel 8 Contact Form with Send Email

In this step by step tutorial I will demonstrate you how to create a contact form in laravel with validation and sending email on form submission.

  1. Install Laravel Project
  2. Setup Database
  3. Create Migration
  4. Add Route
  5. Add Controller
  6. Add Blade.

Step 1: Install Laravel Project

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


Step 2: Setup Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Create Migration

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

After this command you will find one file in following path “database/migrations” and you have to put bellow code in your migration file for create students table

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

Now, we will put following code in Contact model :

App/Models/Contact.php

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

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

Now, we will add following two methods in ContactController

1)contactForm()

2)storeContactForm()

app/Http/Controllers/ContactController.php

Step 6: Add Blade

Now, we will create two blade file contactForm and second is mail file.

1) contactForm.blade.php

2) contactMail.blade.php

So let’s just create following file and put bellow code.

resources/views/contactForm.blade.php

resources/views/contactMail.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 CRUD Operations with Bootstrap 4 Tutorial with Example

In this Laravel 8 Simple CRUD Application with Bootstrap 4 Example Tutorial, you will learn to create a simple CRUD (Create, Read, Update and Delete) application with bootstrap 4 in Laravel 8. In this Laravel 8 CRUD operation example tutorial I’ll show you how to create a simple crud application with bootstrap 4 in laravel 8. In this example we will learn how to create a simple crud operation application in laravel 8.

In this tutorial, you will learn step by step how to build simple crud operation app in laravel 8. And how to validate add & update form data on server-side in laravel 8 crud app.

Laravel 8 CRUD Operations with Bootstrap 4 Tutorial with Example

This laravel 8 crud operation step by step tutorial will implement a simple company crud operation app in laravel 8 app with validation.

  1. Install Laravel Application
  2. Add Database Details in ENV
  3. Organize Model and Migration
  4. Create Controller
  5. Create Routes
  6. Create Blade Partial Views
  7. Set Up Master Layout.

Install Laravel Application

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.

Organize Model and Migration

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

Add the table values in migration file inside the database/migrations/create_employees_table.php:


Define the table values in $fillable array within the app/Models/Employee.php:


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

Create Controller

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

Put the below code in app/Http/Controllers/EmployeeController.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 Partial Views

Create the following files within resources/views:

Set Up Master Layout

In this step we will setup the master layout. Put the following code in main layout.blade.php:


Add the following code in the resources/views/welcome.blade.php file.

Put the given below code in resources/views/index.blade.php to display the employees data in table:

Put code code in resources/views/update.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 –

How to Create AJAX Autocomplete Search in Laravel 8 with Select2

In this How to Create AJAX Autocomplete Search in Laravel 8 with Select2 tutorial, I will show you how to create dynamic ajax driven autocomplete with select2 in laravel. In this tutorial you will learn to create dynamic ajax driven autocomplete with select2 in laravel. In this example we will be using Select2 jQuery plugin in Laravel 8 with AJAX.

How to Create AJAX Autocomplete Search in Laravel 8 with Select2

The jquery Select2 plugin is used to create dynamic autocomplete input with several options. In this example you will learn how to implement Select2 autocomplete in laravel.

  1. Install Laravel 8 Application
  2. Database Configuration
  3.  Create product Table and Model
  4. Create Routes
  5. Create Controller
  6. Create View

Step 1 : Install Laravel Application

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

Step  2: 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: Create product Table and Model

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

After this command you have to put bellow code in your migration file for create product table.

/database/migrations/2020_03_05_100722_create_product_table.php

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

After you have to put bellow code in your model file for create product table.

/app/Product.php

Step 4: Create Route

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

routes/web.php

Step 5: Create Controller

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

In this controller will add following two methods:

1)index()

2)dataAjax()

Now, put the following code in ItemController.php file. /app/Http/Controllers/Select2AutocompleteController.php

Step 6: Create View

In this step we will create laravel blade view file as following:

/resources/views/select2/index.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 Send Email in Laravel 8 with Markdown Template Example

In this tutorial we will learn how to send email in laravel 8 using mailable and mailtrap. We will use Laravel 8 builtin mailable markdown class to send emails. In order to send email using mailtrap we will implement laravel 8 builtin mailable markdown class. In this post I’ll show you how to integrate mailtrap to send email in laravel 8 application.

Laravel 8 provides builtin mailable markdown class to send emails. In Laravel 8 you can use mailtrap, smtp, Mailgun, Postmark, Amazon SES, and sendmail for sending emails. You are required to configure driver details on the .env file.

How to Send Email in Laravel 8 with Markdown Template Example

In this step by step tutorial you will understand how to send emails in Laravel 8 with the help of Mailtrap. We will explain to you how to use Laravel 8 builtin mailable markdown class to send emails using Mailtrap.

  1. Create Laravel Application
  2. Setting Up Mail Configuration
  3. Define Markdown with Mailable Class
  4. Create & Configure Controller
  5. Prepare Route
  6. Evoke Mail View
  7. Start Application

Create Laravel Application

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

Setting Up Mail Configuration

In this step we will be setting smtp detail for mail configuration in Laravel, We will be using following Gmail SMTP details such as username, password inside the .envfile.

If we are sending email from localhost using Gmail SMTP, then it requires you to turn on the “Allow less secure apps” on?. Go to the link provided:

Now, You need to turn on the option “Allow less secure apps”

Define Markdown with Mailable Class

The mailable class in Laravel used for sending emails. Now, lets create a new laravel mailable class using following artisan command:

Once the above command executed, it will create a new laravel mailable class SendDemoMail.php in app/Mail/ directory. Open the SendDemoMail.php file and put the following code in it.

Create & Configure Controller

Now, we will create a controller that will handle the logic to send email. Let’s create ContactController Controller using following command:

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

Controllers/ContactController .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 Email Template

In this step, we will create view/blade file to setup email template. Open resources/views/Email/sendDemoMail.blade.php file, put the following code.

resources/views/Email/sendDemoMail.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 Implement and Use Highcharts in Laravel 8 Project

In this Laravel 8 Highcharts Example Tutorial I will show you how to implement highchart in laravel 8 application. In this tutorial you will learn to implement highchart in laravel 8. In this example I will demonstrate the use of highchart in laravel application. In this example we will fetch month wise data and display month wise data in highcharts for analytics on laravel application.

How to Implement and Use Highcharts in Laravel 8 Project

In this step by step tutorial I will demonstrate you how to implement Highcharts in Laravel 8 application. Please follow the instruction given below:

Step 1: Create web routes

In the first step we will define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 2: Create Controller

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

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

app/Http/Controllers/HighChartController.php

Step 3: Create Blade File

Now, we will create a blade view file. Go to the resources/views/highchart.blade.php and put the below javascript and HTML code for displaying the highchart. So go to the resources/views/ and update the below javascript and HTML code for displaying the highchart:

Remember to include highchart js libraries on your blade file:


Use below javascript as per requirement :

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 Create Send Email Notification in Laravel 8

In this How to Create Send Email Notification in Laravel 8 tutorial I will show you how to create and send email notification in laravel 8. In this tutorial you will learn to create and send email notification in laravel 8.

How to Create & Send Email Notification in Laravel 8

In this step by step tutorial I will demonstrate you how to create and send email notification in laravel 8.

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.

Generate Notification Migration

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

The above command will generate a file at path migrations/create_notifications_table.php:

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

Create Notification Class

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

Put following code in app/Notifications/BillingNotification.php file:

Create Controller

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

Put the following code in app/Http/Controllers/BillController.php

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

Send Email Notification in Laravel 8

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

Now, visit the following URL in browser to Send Email Notification in Laravel 8

How to Create Reusable Code with Laravel 8 Traits

In this How to Create Reusable Code with Laravel 8 Traits tutorial I will show you how to create reusable code in Laravel 8 application. In this tutorial you will learn to create laravel traits  to generate reusable code. In this article I will share example to create and use laravel traits

What Is Laravel Traits?

In laravel, traits is a independent reusable class that is that allows you to implement single inheritance in order to reuse it.

How to Create Reusable Code with Laravel 8 Traits

In this step by step tutorial I will demonstrate you with example how to create an use laravel traits.

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 Run Migrations

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

Now, open database/migrations/xxx_products_table.php file and put the following code.


Put below code in app/Models/Product.php:


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

Create Test Data

In this step we will add some test data in product table. Add product table’s value in database/seeds/DatabaseSeeder.php file, it will generate dummy data in database.

Let’s seed database with test records:

Create Laravel Traits File & Folder

Lets create a Traits folder inside app/Http/ directory, then create ProductTrait.php file within the Traits folder. Now, you need to place the following code in app/Http/Traits/ProductTrait.php file:

Using Reusable Code with Laravel Traits

Place code in app/Http/Controllers/ProductController.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

Now, place the below code in resources/views/welcome.blade.php view file to display the data in tabular form with the help of Laravel Traits:

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 –

Login with Facebook in Laravel 8 with Socialite and Jetstream

In this Login with Facebook in Laravel 8 with Socialite and Jetstream tutorial I’ll show you how to integrate facebook login in laravel 8 using Socialite and Jetstream package. Integrating Facebook login in Laravel 8 using Socialite and Jetstream package is much easier. Allowing users to login with their social media accounts makes registration/login process much easier, it also encourages more users to register for your application.

Login with Facebook in Laravel 8 with Socialite and Jetstream

In this step by step tutorial, you will learn to integrate Facebook login in your laravel 8 application using Socialite and Jetstream. Please follow the steps give 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.

.env

Step 3 : Install Jetstream

In this step we will Install Laravel Jetstream Package via Composer using following command:

Now, you have to install livewire with jetstream. Use the following command to install livewire with jetstream in laravel application:

Install necessary NPM dependency:

Start node development server:

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

Step 4 : Install Socialite

In this step we will Install Socialite Package via Composer using following command:

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

config/app.php

Step 5: Create Facebook App

Step 1:-

Go to Facebook’s developers site https://developers.facebook.com/ and log in with your Facebook account. There in Facebook developers Dashboard you have option to Create App. Lets create a Facebook Login App simply providing App Name and Contact Email.

Step 2:-

After creating the facebook app, go to setting->advanced and set redirect url

Step 3:-

Then, go to Facebook Login -> Settings and scroll down to “Valid OAuth Redirect URL” and set your callback URL

Step 4:-

After creating app, go to Settings -> Basic and get your newly created App ID and App Secret.

Now, go to config directory and open service.php file and add the client id, secret and callback url:

Step 6: Add Database Column

database/migrations/2020_09_18_052105_add_facebook_id_column_in_users_table.php

Now, you need to update User model as following:

app/Models/User.php

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

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

Now, go to app/http/controllers/ directory and open FacebookController.php. Then put the following code into your FacebookController.php file

app/Http/Controllers/FacebookController.php

Step 9: Update Blade File

Now, we will add facebook login button into login.blade.php file. So, open login.blade.php, which is found inside resources/views/auth/ directory:

resources/views/auth/login.blade.php

Step 10: 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 Angular JWT Password Reset with Mailtrap Example

In this Laravel 8 Angular JWT Password Reset with Mailtrap Example Tutorial, I will show you how to create reset password feature in the Laravel 8 angular application with JWT auth and mailtrap. In this tutorial you will learn to create a password reset functionality in laravel and Angular using REST API with JWT Authentication and Mailtrap.

In this example we will create laravel APIs for reset password request and to reset the password. We will capture password reset request with the token. We will be using mailtrap to send password reset mail.

Laravel 8 Angular JWT Password Reset with Mailtrap Example

In this step by step tutorial I will demonstrate you how to create a password reset functionality with mailtrap in Angular using Laravel 8 REST API with JWT Authentication

  1. Clone Laravel Token-Based Authentication Repo
  2. Configure Mailtrap
  3. Reset Password Request
  4. Reset Password

Clone Laravel Token-Based Authentication Repo

In this step we will clone the repo using the following command:

Configure Mailtrap

Then, open .env and add the mailtrap details.

Password Reset Request

In this step we will create a controller PasswordResetRequestController using following command:

Open PasswordResetRequestController.php and place the following code.

Next we will create a mailable class for mail template and sending the mail.

Open App/Mail/SendMail.php and put the following code:

Consume Password Reset Request API

Next go to frontend/app/shared/auth.service.ts and put the following code in it:

Create Reset Password Form

Now, we will create a password reset form

Inside the frontend folder, add the following code in change-password-request.component.ts file.


Place the following code in change-password-request.component.html file.

Create Password Reset Mail Template

Now, go to views/Email/resetPassword.blade.php and put the following code in it to create the mailer template.

Laravel Password Reset Example

Set the authorize to true and define email and password fields inside the backend folder’s
app/Http/Requests/UpdatePasswordRequest.php.


Next, we have to create change password controller inside the backend folder. Use the following command to generate ChangePasswordController controller:


Now. Open ChangePasswordController.php and put the following code:


Now go to resources/routes/api.php and put the following code.

Register Password Update API in Service

Now, go to  frontend/app/shared/auth.service.ts and put the following code in it:

Create Password Update Form

Inside the frontend folder, open change-password.component.ts file and put the following code in it.


Inside the frontend folder, open change-password.component.html file and put the following code in it.

Define Angular Routes

Now, lets define some angular routes inside the app-routing.module.ts file.

Run Application

Start Laravel App
Now switch to the laravel project directory and run the app using following command:


Run Angular App

Now switch to angular project directory and run the angular project.