Category Archives: Blog

Blog

Laravel 8 Download File From URL to Public Storage Folder

In this laravel download file from public storage folder example, I’ll show you how to download or display files from public storage folder in laravel 8 application. In this tutorial you will learn how to download or display files from public storage folder in laravel 8. In this article I will share example to display and download file from public storage folder in laravel 8.

Laravel 8 Download File From URL to Public Storage Folder

In this step by step tutorial I’ll guide you through the step to download files from public storage folder. And as well as display files on laravel blade views:

Steps 1: Routes

In this step, you need to add the following routes on web.php file. Go to routes directory and open web.php file then update the routes as following:

web.php

Step 2: Create Controller File

Now, go to app/controllers and create a controller file named FileController.php. Then update put the following methods in it:


The above code will download files from public storage by giving the file name and return a response with correct content type. To display files on blade views, so you have to update the following methods into your controller file:

The above lined of code fetches the image files from the public storage folder and extract the name of these files and you pass them to your view.

Step 3: Create Blade View

Now, go to resources\view folder and create a blade view file named show.blade.php. Then update the following code into it:

In Laravel 5,6,7,8, you can do this for a local file to download it:


You can download external image using copy() function, then send it to user in the response:

Note that, if you are getting the following errors in laravel apps, when you are working with laravel files or storage:

1: “class ‘app\http\controllers\file’ not found”.

Import File in your controller file as follow:

2: “class ‘app\http\controllers\response’ not found”.

Import Response in your controller file as follow:

3: “class ‘app\http\controllers\storage’ not found”.

Import Storage in your controller file as follow:

Laravel 8 Send SMS Notification to Mobile/ Phone Example

In this Laravel 8 Send SMS Notification to Mobile/ Phone Example tutorial I will show you how to send SMS notification to mobile in laravel 8 application. In this tutorial you will learn to send sms notification to mobile in laravel. In this example we will be using nexmo sms package to send sms in laravel 8 application.

Laravel 8 Send SMS Notification to Mobile/ Phone Example

In this step by step tutorial I will demonstrate you with example how to send sms notification in laravel 8 application using nexmo sms package. Please follow instruction given below:

  • Step 1 – Download Laravel 8 Application
  • Step 2 – Connecting App to Database
  • Step 3 – Install SMS Package
  • Step 4 – Create Route
  • Step 5 – Create Controller By Artisan Command
  • Step 6 – 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 – Connecting App 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.

Step 3 – Install SMS Pakcage

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

Visit the link given below and create a nexmo account there:

After creating account you will be provided app id and secret key.

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 – Create Controller By Artisan Command

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

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

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 Livewire Dependent Dropdown Tutorial

In this Laravel 8 Livewire Dependent Dropdown Example tutorial, I’ll show you how to create dependent dropdown with Livewire in laravel 8. In this tutorial you will learn to implement dependent dropdown with Livewire in laravel 8. In this article we will be creating simple country state city dependent dropdown example to demonstrate dependent dropdown example in laravel.

Laravel 8 Livewire Dependent Dropdown Tutorial

In this step by step Laravel 8 Livewire Dependent Dropdown tutorial I will demonstrate you how to create Livewire Dependent Dropdown in laravel 8 application. Please follow instruction given below:

  • Step 1: Install Laravel 8 App
  • Step 2: Add Database Detail
  • Step 3: Create Migration For File using Artisan
  • Step 4: Create Model File
  • Step 5: Install Livewire Package
  • Step 6: Create Dependent Dropdown Component using Artisan
  • Step 7: Add Route For Livewire Dependent Dropdown
  • Step 8: Create View File
  • Step 9: Run Development Server

Step 1: Install Laravel 8 App

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

Step 2: Add Database Detail

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 For File using Artisan

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

Now, go to database/migrations folder and open create_states_cities_tables.php file. Then update the following code into create_states_cities_tables.php file:

Step 4: Create Model File

Now, we will create model file. Please run the following command:

Then visit app/Models/ directory and open state.php file and add the following code into it:

Then visit app/Models/ directory and open city.php file and add the following code into it:

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

Step 5: Install Livewire Package

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

Step 6: Create Dependent Dropdown Component using Artisan

In this step we will create a livewire component for country state city dropdown functionality:

The above command will create the component on the following path:

Now, go to app/Http/Livewire folder and open Statecitydropdown.php file. Then add the following code into your Statecitydropdown.php file:


Now, go to resources/views/livewire folder and open statecitydropdown.blade.php file. Then add the following code into your statecitydropdown.blade.php file:

Step 7: Add Route For Livewire Depedent Dropdown

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

In this step we will create blade view files. Go to resources/views/livewire folder and create one blade view files that name app.blade.php file. Then put the following code into your app.blade.php file:

Step 9: Run Development Server

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

Now, open the following URL in browser to see the output –

Laravel 8 Livewire Click Event Tutorial Example

In this Laravel 8 livewire click event tutorial example tutorial I will show you how to implement click event with livewire in laravel 8 application. In this tutorial you will learn to implement or create click event using livewire in laravel 8. In this article I will share example to create livewire click event in laravel.

Laravel 8 Livewire Click Event Tutorial Example

In this step by step tutorial I will demonstrate you how to implement click event with livewire in laravel 8 application. Please follow the instruction given below:

  • Step 1: Install Laravel 8 App
  • Step 2: Add Database Detail
  • Step 3: Install Livewire Package
  • Step 4: Create Click Event Component using Artisan
  • Step 5: Add Route For Livewire Click Event
  • Step 6: Create View File
  • Step 7: Run Development Server

Step 1: Install Laravel 8 App

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

Step 2: Add Database Detail

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.

Step 3: Install Livewire Package

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

Step 4: Create Click Event Component using Artisan

Now we will create a livewire click event component using following artisan command:

The above command will create the following components on the following path:

Now, go to app/Http/Livewire folder and open ClickEvent.php file. Then add the following code into your ClickEvent.php file:


Now, go to resources/views/livewire folder and open click-event.blade.php file. Then add the following code into your click-event.blade.php file:

Step 5: Add Route For Livewire Click Event

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 6: Create View File

In this step we will create blade view file. Go to resources/views/livewire folder and create one blade view files that name app.blade.php file. Then add the following code into your app.blade.php file:

Step 7: 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 Create Custom Blade Directive

In this Laravel Create Custom Blade Directive tutorial I will show you how to create custom blade directive in laravel. In this tutorial you will learn to create custom blade directives in laravel. In this article I will share example to create custom blade directives.

In laravel you can create your own @var, @if, @case directive that help you to avoid rewrite same code multiple time so that you can reuse.

Laravel Create Custom Blade Directive

In this step by step tutorial we will be creating custom blade directives and reuse it in blade file. we will create @nl2br blade directive and use it with example. Please follow the instruction given below:

Step 1: Create Custom Blade Directive

First of all you have to declare custom blade directive in your app service provide file:

app/Providers/AppServiceProvider.php

Step 2: 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 3: Create Blade File

Now you can use @nl2br directive in this blade file as following:

Laravel 8 Livewire Select2 Dropdown Tutorial Example

In this Laravel 8 livewire select2 example tutorial I will show you how to implement livewire select2 dropdown in laravel 8 application. In this tutorial you will learn to implement livewire select2 dropdown in laravel 8. In this article I will share example to implement livewire select2 dropdown in laravel 8 application.

Laravel 8 Livewire Select2 Dropdown Tutorial Example

In this step by step tutorial I will demonstrate you with example how to create livewire select2 dropdown in laravel 8 application. Please follow the instruction given below:

  • Step 1: Install Laravel 8 App
  • Step 2: Add Database Detail
  • Step 3: Install Livewire Package
  • Step 4: Create Select2 Component using Artisan
  • Step 5: Add Route For Livewire Select2
  • Step 6: Create View File
  • Step 7: Run Development Server

Step 1: Install Laravel 8 App

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

Step 2: Add Database Detail

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 the migration to create database table using following artisan command:

Step 3: Install Livewire Package

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

Step 4: Create Select2 Component using Artisan

In this step we will create a livewire component for creating a livewire select2 dropdown component using the following command:

This command will create the following components on the following path:

Now, go to app/Http/Livewire folder and open Select2.php file. Then put the following code into your Select2.php file:


Now, go to resources/views/livewire folder and open select2.blade.php file. Then add the following code into your select2.blade.php file:

Step 5: Add Route For Livewire Select2

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 6: Create View File

In this step we will create blade view file. Go to resources/views/livewire folder and create one blade view files that name app.blade.php file. Then add the following code into your app.blade.php file:

Step 7: 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 Send SMS to Mobile with Nexmo Example

In this Laravel 8 Send SMS to Mobile with Nexmo Example tutorial I will show you how to send SMS message to mobile in laravel 8 application. In this tutorial you will learn to send sms to mobile in laravel. In this example we will be using nexmo sms package to send sms message in laravel 8 application.

Laravel 8 Send SMS to Mobile with Nexmo Example

In this step by step tutorial I will demonstrate you with example how to send sms message in laravel 8 application using nexmo sms package. Please follow instruction given below:

  • Step 1 – Download Laravel 8 Application
  • Step 2 – Connecting App to Database
  • Step 3 – Install SMS Package
  • Step 4 – Create Route
  • Step 5 – Create Controller By Artisan Command
  • Step 6 – 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 – Connecting App 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.

Step 3 – Install SMS Pakcage

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

Visit the link given below and create a nexmo account there:

After creating account you will be provided app id and secret key.

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 – Create Controller By Artisan Command

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

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

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 Find Nearest Location By Latitude and Longitude

In this Laravel 8 Find Nearest Location By Latitude and Longitude tutorial I will show you How to find nearest location using latitude and longitude in laravel 8 application. In this tutorial you will learn How to find nearest location using latitude and longitude in laravel 8. In this article I will share example to find nearest location using latitude and longitude in laravel 8 application. When developing any web application we come to situations where we need to find the nearest location using latitude and longitude in laravel. In this tutorial I will help you find nearest location using your current latitude and longitude in laravel 8. In this examplewe will find neareby place using latitude and longitude query in laravel eloquent. You can get nearest geolocation by mysql radius query laravel 8.

Laravel 8 Find Nearest Location By Latitude and Longitude

In this step by step tutorial I will demonstrate you How to find nearest location using latitude and longitude in laravel 8. Please follow the instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Add Route
  • Step 4 – Generate Controller by Command
  • Step 5 – Run Development Server
  • Step 6 – Test This App

Step 1 – Install Laravel 8 App

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

Step 2 – Connecting App 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.

Step 3 – 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 4 – Generate Controller by Command

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

After successfully create controller go to app/controllers/LocationController.php and update the following code :

Step 5 – 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 and Read XML File Tutorial Example

In this Laravel 8 Generate and Read XML File Tutorial Example tutorial I will show you how to read xml file in laravel 8 application. In this tutorial you will learn to generate and read xml file in laravel 8 application. In this article I will share example to generate and read xml file in laravel 8 application.

Laravel 8 Read XML File Tutorial Example

In this step by step tutorial I will demonstrate you how to read xml file in laravel. Please follow the instruction given below:

Create Sample XML File

Please create a sample xml file with below code and save it as name “sample-course.xml” and save it in public directory:

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.

Create Controller

In this step we will create a controller to parse or read xml data from file using following command:

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

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

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 Eloquent firstWhere() Example

In this Laravel Eloquent firstWhere() Example tutorial I will show you how to use Eloquent firstWhere() method in laravel. In this tutorial you will learn about the use case and how to use Eloquent firstWhere() method in laravel model query. In this article I will share various example to use Eloquent firstWhere() method in laravel application.

What Is Eloquent firstWhere() method?

The eloquent firstWhere() method returns the first element in the collection with the given key / value pair. In laravel eloquent firstWhere() method will help you to easily fetch match first record.

Laravel Eloquent firstWhere() Example

The FirstWhere method returns the first element in the collection with the given key / value pair.

Example 1:

Output

Example 2:

Output

Example 3:

Output:

 

Laravel 8 Botman Chatbot Tutorial Example

In this Laravel 8 Botman Chatbot Tutorial Example tutorial I will show you how to install or integrate botman chatbot in laravel 8 application. In this tutorial you will learn to integrate and install botman chatbot in laravel 8. In this article I will share example to integrate botman chatbot in laravel 8 application.

Laravel 8 Botman Chatbot Tutorial Example

In this step by step tutorial I will demonstrate you how to integrate botman chatbot in laravel 8 application.Please follow the instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Install Botman and Botman Driver
  • Step 4 – Create Configuration File
  • Step 5 – Add route
  • Step 6 – Create Controller by Artisan Command
  • Step 7 – Create Blade File
  • Step 8 – Run Development Server

Step 1 – Install Laravel 8 App

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

Step 2 – Connecting App 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.

Step 3 – Install Botman and Botman Driver

In this step we will install botman and botman driver in laravel. Run following command to install botman composer package:

Install Botman:

Install Botman Driver:

Step 4 – Create Configuration File

In this step we will create configuration file for driver and cache.

config/botman/config.php

config/botman/web.php


Now, run following command to migrate database schema.

Step 5 – 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 6 – Create Controller by Artisan Command

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

Now, go to app/http/controller/BotManController.php. and update the following methods into your controller file:

Step 7 – Create Blade File

In this step we will create blade view file. Go to resources/views directory and open file that named welcom.blade.php. Then put the following html and javascript code into this blade view file:

Step 8 – Run Development Server

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

Laravel 8 Full Text Search using Ajax Example

In this Laravel 8 Full Text Search using Ajax Example Tutorial I’ll show you how to implement ajax full text search in laravel using full text search package. In this tutorial we will guide you step by step on how to implement ajax full text search in laravel using full text search package. In this tutorial I’ll guide you with example of creating ajax full text search with mysql DB in laravel app.

Laravel 8 Full Text Search using Ajax Example

In this step by step tutorial I will demonstrate you with example on how to implement ajax full text search in laravel using full text search package. Please follow the instruction given below:

  • Step 1: Install Laravel New App
  • Step 2: Configuration .evn file
  • Step 3: Run Migration
  • Step 4: Install Full Text Search Package
  • Step 5: Add Fake Records in DB
  • Step 6: Add Routes,
  • Step 7: Create Controller
  • Step 8: Create Blade View
  • Step 9: Start Development Server

Step 1: Install Laravel Fresh Setup

In this tutorial, you will learn to integrate Razorpay payment gateway in your laravel 8 project. Follow this step by step tutorial to learn Razorpay payment gateway integration in laravel 8.

Step 2: 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 3: Run Migration

Now, run following command to migrate database schema.

Step 4: Install Full Text Package

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

Step 5: Add Fake Records in DB

Now, we will generate some fake records using following command:

Then use the following command to create Model class for builder database query:

Then visit app/Models/Full_text_search.php And the following code into it:

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

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

Then go to app/Http/Controllers directory and open FullTextSearchController.php file. And put the following code into FullTextSearchController.php file:

Step 8: Create Blade View

In this step we will create blade view file. Go to resources/views/ directory and create one blade view file named full-text-search.blade.php file. Then put the following code into your full-text-search.blade.php file:

Step 9: Start Development Server

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

Now, open the following URL in browser to see the output –

or