Category Archives: Laravel

Laravel Tutorials

Laravel 7 Please Provide a Valid Cache Path

In this Laravel 7 Please Provide a Valid Cache Path tutorial, I’ll show you how to fix the issue Laravel 7 Please Provide a Valid Cache Path.

Laravel 7 Please Provide a Valid Cache Path

When deploying a laravel project on the webserver or virtual host. You conmanly face issue that  “please provide a valid cache path laravel”. This error  “please provide a valid cache path laravel” mainly occurs, because your laravel project  does not have some required directories/folders. The directories and folders are the following:

storage/framework/
sessions
views
cache

In this article I’ll share 3 different solutions to fix this “please provide a valid cache path laravel” on your server or virtual host.

Solution 1 : How to fix laravel “Please Provide a Valid Cache Path”

In this soluction you have to create a framework folder inside your laravel-project-name/storage/ directory by using the following command:

Now you have to set permissions to the directory. To allow Laravel to write data in the above-created directory. So run the following command on your command prompt:

Solution 2 : Laravel “Please Provide a Valid Cache Path” error

In this method you have to create manually directories inside your laravel project folder. Go to your project root directory and open Storage folder and Create framework directory/folder inside the storage folder. Once you have create following directories inside the framework folder.

  • sessions
  • views
  • cache
  • cache/data:- Inside cache folder, create a new directory/folder named data.

Open your terminal and run the following command to clear all the cache:

Solution 3 : “Please Provide a Valid Cache Path” error in laravel

In this method  you have to open your terminal and run the following commands:

Laravel Csrf Token Mismatch on Ajax Request

In this Laravel csrf token mistatch tutorial I’ll show you how to fix csrf token mismatch issue in laravel while using ajax method.

Laravel Csrf Token Mismatch on Ajax Request

In laravel while making ajax method call with laravel form that time you may commonly get an error message related to csrf token mismatch and 419 status code in laravel app. Following is list of common issues:

  • csrf token mismatch laravel ajax
  • message csrf token mismatch in ajax call
  • csrf token mismatch laravel api
  • axios csrf token laravel
  • laravel csrf token expiration time
  • csrf token mismatch laravel postman
  • laravel csrf token mismatch on ajax post a second time
  • send token in ajax in laravel

In this tutorial I’ll share two different method to fix csrf token mismatch error in laravel and ajax.

How to fix CSRF Token Mismatch error in Laravel

In this this method you have to open your blade view file and add the following line of code into head section of your blade file.

Next, you have to open again your blade view file. Then get the csrf token and add with ajax code in laravel:

Fix CSRF Token Mismatch Laravel

In this method to fix the status code: 419 unknown status and csrf token mismatch with your ajax request in laravel. So, you can try this method to fix the issue:

open your blade view file and add the following line of code into your blade view file head section:

Now modify your ajax request as following to send csrf token with your form data using ajax in laravel:

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 –