Category Archives: Laravel

Laravel Tutorials

Laravel 8 Joins Example Tutorial

In this Laravel 8 eloquent join example tutorial I will show you how many types of join and subquery join in laravel you will also learn to use laravel join with eloquent queries. In this tutorial you will learn about various joins in laravel eloquent model. In this article I’ll demonstrate the use of various types of laravel joins. In this step by step laravel 8 join tutorial I will share example of laravel eloquent join (join, left join, right join, cross join, and advance join) and subquery join.

Laravel 8 Eloquent Join Example Tutorial

In this Laravel 8 Eloquent Join Example Tutorial we will learn about following laravel eloquent join query with examples:

 

Types of Joins In Laravel 8

  • Laravel Inner Join
  • Laravel Left Join
  • Laravel Right Join
  • Laravel Cross Join
  • Laravel Advanced Join
  • Laravel Sub-Query Joins

1: Laravel Join Eloquent

In laravel if we join two tables it selects records if the given column values matching in both tables. It’s also known as laravel inner join eloquent.  Let’s say you have two tables, users and posts. Both have ID columns, and there is a user_id in the post, which is a foreign key for the users’ table.’

Example 1: Laravel Eloquent Join() with 2 Tables

When you dump the above laravel join query, you will get the following SQL query:

Example 2: Laravel Eloquent Join() with 3 Tables

When you dump the above laravel join 3 table query, you will get the following SQL query:

Example 3: Laravel Eloquent Join() with Multiple Conditions

When you dump the above laravel join with multiple conditions query, you will get the following SQL query:

2 – Laravel Left Join

Laravel left join query returns all rows from the left table, even if there is no matches in the right table. When you are using laravel left join eloquent with a query builder laravel left join fetch data from the left table. Even if there is no match in the right table.

Example 1: Laravel Left Join Query

When you dump the above laravel left join query, you will get the following SQL query:

Example 2: Laravel Left Join with Multiple Condition

When you dump the above laravel left join with multiple conditions query, you will get the following SQL query:

3 – Laravel Right Join

Laravel right join query returns all rows from the right table, even if there is no matches in the left table. When you are using laravel right join eloquent with a query builder laravel right join fetch data from the right table. Even if there is no match in the left table.

Example 1: Laravel Right Join Query

When you dump the above laravel right join query, you will get the following SQL query:

Example 2: Laravel Right Join with Multiple Condition

When you dump the above laravel right join with multiple conditions query, you will get the following SQL query:

4 – Cross Join Clause

In laravel, the cross join selects every row from the first table with every row from the second table.

5 – Laravel Advanced Join

If in join query add some addition criteria with where clause it termed as advance join query.

6 – Laravel Sub-Query Joins

In this laravel join example we are using join query in sub query.

Laravel 8 Generate PDF with Graph Tutorial

In this Laravel 8 Generate PDF with Graph tutorial, I’ll show you how to generate pdf with graph in laravel 8 application. In this tutorial you will learn to generate pdf file with graph in laravel. In this article we will create example to Generate PDF with Graph. We will be using wkhtmltopdf Software to generate pdf file in this tutorial.

Laravel 8 Generate PDF with Graph Tutorial

In this Laravel 8 Generate PDF with Graph Tutorial I will guide you step by step how to generate pdf with graph in laravel 8 application.

  • Step 1 – Install wkhtmltopdf Software
  • Step 2 – Install Laravel 8 App
  • Step 3 – Install mikehaertl/phpwkhtmltopdf
  • Step 4 – Add Routes
  • Step 5 – Create Controller by Command
  • Step 6 – Create Blade View
  • Step 7 – Run Development Server
  • Step 8 – Test This App

Step 1 – Install wkhtmltopdf Software

For Ubuntu:

For Windows:

You have go the following link and download exe. Then install it:

Step 2 – Install Laravel 8 App

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

Step 3 – Install mikehaertl/phpwkhtmltopdf

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

Step 4 – Add 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 Command

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

The above command will create a controller file GraphPdfController.php in app/Http/Controllers folder. Now, go to app/Http/Controllers and open GraphPdfController.php. Then put the following code into your controller file:

Step 6 – Create View File

Go to resources/views/ folder and create a new blade view file that name graph.blade.php file. After that, update the following code into your graph.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 Fetch Data using Ajax Tutorial Example

In this Laravel 8 Fetch Data using Ajax Tutorial Example tutorial I will show you how to fetch data from database using ajax in laravel 8 applications. In this tutorial you will learn to use ajax in laravel 8. In this article I will demonstrate you how to fetch records from database using ajax in laravel. Using ajax you can fetch data from database without reloading page in laravel 8. In this step by step guide you will understand laravel ajax request implementation.

Laravel 8 Fetch Data using Ajax Tutorial Example

In this step by step tutorial I will demonstrate you with example how to fetch data using ajax in laravel 8 application. Please follow instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Execute Database Migration Command
  • Step 4 – Add Routes
  • Step 5 – Create Controller Using Artisan Command
  • Step 6 – Create Blade Views
  • Step 7 – Start Development Server
  • Step 8 – 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 – Execute Database Migration Command

Now, run following command to migrate database schema.

Step 4 – Add 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 Using Artisan Command

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

Now, open this controller file located inside app/http/controllers directory:

Step 6 – Create Blade Views

In this step we will create a blade view file named list.blade.php file. So, go to the resources/views directory and create list.blade.php file. Then put the following code into the list.blade.php file:


After that, create one modal for display data on it using ajax. So add the following code into list.blade.php file:


Now, add the following javascript code into list.blade.php file for display data on modals using ajax in laravel 8 app:

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 Create Unique Slug Tutorial Example

In this Laravel 8 Create Unique Slug Tutorial Example I will show you how to generate unique slug for blog posts title in laravel application. In this tutorial you will learn to generate unique slug for post title in laravel 8. In this example I will demonstrate you to generate unique slug or seo friendly slug url for post title in laravel 8. We will be using cviebrock eloquent sluggable laravel package for generating seo friendly url in laravel 8.

Laravel 8 Create Unique Slug Tutorial Example

In this step by step tutorial I will demonstrate you how to generate unique slug in laravel application. Please follow instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Install Eloquent Sluggable Package
  • Step 4 – Build Model and Migration
  • Step 5 – Add Routes
  • Step 6 – Create Controller using Artisan Command
  • Step 7 – Create the blade view
  • Step 8 – Start Development Server

Step 1 – Install Laravel 8 App

First of all we need to create a fresh laravel project, download and install Laravel 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 Eloquent Sluggable Package

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

After installing eloquent sluggable package, run the following command:

Step 4 – Build Model and Migration

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

The above command will create a model name Post and also create a migration file for the post table. Now put the following code in it:

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

Now, add the fillable property in Post.php file, which is placed inside app/models directory:

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

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

Now, go to app/HTTP/Controller directory and open PostController.php file. And put the following code into it:

Step 7 – Create the blade view

Now we will create following blade files:

  • List.blade.php
  • Create.blade.php

List.blade.php

Create.blade.php

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 –

Laravel 8 FullCalendar Ajax Tutorial with Example

In this Laravel 8 FullCalendar Ajax Tutorial I’ll show you how to display events on the calendar using fullcalendar components in laravel 8  application. In this tutorial you will learn to display events on the calendar using fullcalendar in laravel 8. This tutorial you will also learn to show dynamic event data on calendar using fullcalendar components in laravel 8.

Laravel 8 FullCalendar Ajax Tutorial with Example

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

  • Step 1 – Install Laravel App
  • Step 2 – Connecting App to Database
  • Step 3 – Build Migration & Model
  • Step 4 – Add Routes
  • Step 5 – Create Controller Using Artisan Command
  • Step 6 – Create Blade View
  • Step 7 – Run Development Server
  • Step 8 – Test This App

Step 1 – Install Laravel 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 – Build Migration & Model

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

The above command will create a model name Event and also create a migration file for the Events table.Now go to database/migrations folder and open create_events_table.php file. Then put the following code into create_events_table.php file, as follow:


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

Step 4 – Add 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 Using Artisan Command

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

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

Step 6 – Create Blade view

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

Put the script on fullcalendar.blade.php, after the closing of the body tag

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 Image Crop & Upload using jQuery and Ajax Example

In this Laravel 8 Image Crop & Upload using jQuery and Ajax Example tutorial I’ll show you how to upload and crop image using jquery ajax in laravel 8. In this tutorial you will learn to upload and crop image before upload using jquery ajax in laravel. In this step by step guide I will demonstrate you to upload and crop image in laravel 8 using jquery ajax.

Laravel 8 Image Crop & Upload using jQuery and Ajax Example

In this step by step tutorial I will demonstrate you how to upload and crop image using jQuery in laravel 8. Please follow the instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Create Crop Image Migration & Model
  • Step 4 – Add Routes For Crop Image Upload
  • Step 5 – Create Crop Image Controller Using Command
  • Step 6 – Create Crop Image Upload Blade View
  • Step 7 – Make Upload Folder
  • Step 8 – Run Development Server
  • Step 9 – Test This App

Step 1 – Install Laravel 8 App

First of all we need to create a fresh laravel project, download and install Laravel 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 – Create Crop Image Migration & Model

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

Now, go to database/migrations folder and open create_images_table.php. Then put the following code into create_images_table.php:

Now run the following command to migrate the table into your select database:

Step 4 – Add Routes For Crop Image Upload

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 Crop Image Controller Using Command

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

Now go to app/http/controllers/ folder and open CropImageUploadController.php. Then put the following file uploading methods into your CropImageUploadController.php file:

Step 6 – Create Crop Image Upload Blade View

In this step, create a blade view file named image-crop.blade.php. Go to /resources/views and create one file name image-crop.blade.php. Then put the following code into your image-crop.blade.php file:

Step 7 – Make Upload Folder

Now, create one folder name upload inside 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 –

Currency Converter in Laravel 8

In this Laravel 8 Currency Converter tutorial I will show you how to create live Currency Converter in laravel. In this tutorial you will learn to integrate or implement live Currency Converter in laravel. In this tutorial, we will learn how to create Currency Converter in laravel applications without using any package with examples.

Currency Converter in Laravel 8

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

  • Step 1 – Install Laravel 8 App
  • Step 2 – Signup and Get API KEY
  • Step 3 – Create Route
  • Step 4 – Create Controller Using Artisan Command
  • Step 5 – Create the blade view
  • Step 6 – Start Development Server
  • Step 7 – 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 – SignUp and Get API KEY

Now visit the link given below to obtain API Key from there.:

Step 3 – 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 4 – Create Controller using Artisan Command

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

The above command will create a controller name CurrencyController. Now, open CurrencyController.php file and put the following code into it.

Step 5 – Create the blade view

In this step we will create a blade files, Go to app/resources/views/ and create one blade view name currency.blade.php. After successfully create the blade view file, update the below-given code into your currency.blade.php file:

currency.blade.php

 

Step 6 – Run Development Server

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

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

How to Check User Login Online Status & Last Seen in Laravel 8?

In this How to Check User Login Online Status and Last Seen in Laravel 8 tutorial I’ll show you how to check User Online, last seen and Not online in Laravel 8 using custom middleware. In this tutorial you will learn to check user is online or not in laravel. In this step by step guide we will be creating a custom middleware to check User Online, Not online and last seen.

How to Check User Login Online Status & Last Seen in Laravel 8?

In this step by step tutorial I will demonstrate you with example How to Check User Login Online Status and Last Seen in Laravel 8. Please follow the instruction given below:

  • Step 1: Install Laravel 8 App
  • Step 2: Connecting App to Database
  • Step 3: Generate Auth Scaffolding
  • Step 4: Add Column in User Table
  • Step 5: Create a Middleware
  • Step 6: Register Middleware in Kernel
  • Step 7: Create Controller by Artisan
  • Step 8: Check Online Status in Blade 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: 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: Generate Auth Scaffolding

In this step we will be generating laravel’s auth scaffolding using following command:

Step 4: Add Column in User Table

You need to add one column in the users table called last_seen. So, navigate database>migrations folder and open create_users_table file. Then update the last_seen column in this file as follow:


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

Step 5: Create a Middleware

In this step we will creating custom middleware using following command:

Now, go to app>Http>Middleware and open ActivityByUser.php middleware. Then put the following code into your middleware file:

Step 6: Register Middleware in Kernel

In this step, navigate app>Http and open Kernel.php. And register ActivityByUser.php middleware in the kernal.php file. You can see as follow:

Step 7: Create Controller by Artisan

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

Now, go to app>Http>Controllers and open UserController.php file. Then update the following method into your UserController.php file:

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: Check Online Status in Blade File

Go to resources>views and open home.blade.php. Then update the following code into home.blade.php.

Step 9: Run Development Server

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

Laravel 8 Typeahead JS Autocomplete Search Example

In this Laravel 8 Typeahead JS Autocomplete Search Example tutorial, I will show you how to create a dynamic database driven ajax jquery autocomplete using typeahead js in Laravel. In this tutorial we will create a dynamic search dropdown autocomplete which will fetch options from database table using bootstrap typeahead js.

The Typeahead JS is a jquery plugin, it is used to create dynamic autocomplete input with several options. In this example you will learn how to implement typeahead autocomplete in laravel.

Laravel 8 Typeahead JS Autocomplete Search Example

In this step by step tutorial I will demonstrate how to create a dynamic database driven ajax jquery autocomplete using typeahead js in Laravel. Please follow the instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Generate Fake Records
  • Step 4 – Add Routes
  • Step 5 – Create Controller & Methods
  • Step 6 – Create Blade View
  • Step 7 – Start Development Server
  • Step 8 – Test This App

Step 1 – Install Laravel 8 App

First of all we need to create a fresh laravel project, download and install Laravel 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 – Generate Fake Records

In this step we will insert dummy data into database

Now we will add fake records in our database. use the below command and add 100 fake records in database :

Step 4 – Add 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 & Methods

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

After successfully create controller go to app/controllers/AutoCompleteController.php and put the below code :

Step 6 – Create Blade View

In this step we need to create blade view file. Go to app/resources/views and create one file name search.blade.php . After create blade file put the below html code here with jquery ui and css library file :

Step 7 – 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 –

Laravel 8 Query Scope Example

In this Laravel 8 Query Scope Example Tutorial I will show you how to use query scopes in laravel eloquent model. In this tutorial you will learn to implement and use query scopes in laravel eloquent model. I will Also show you how to create and use dynamic query scope in laravel applications.

Laravel 8 Query Scope Example

In this step by step guide I will demonstrate you to create and use dynamic query scope in laravel applications.

Create Basic Scope in Model

Here we will first create a basic scope. Go to app/Post.php and create a scope here:

app/Post.php

Use Basic Query Scope on Controller:

We can use basic query scope as following:

Laravel 8 Create Dynamic Scope in Model

Now we are creating a dynamic query scope in laravel model as following:

Dynamic Scope Query On Controller

We can use dynamic scope in laravel as following:

Laravel 8 Apply Scope with Relationship

Here, you will learn how to use query scopes with laravel relationship. Go to your App/Category.php and create a relationship between Categories and Posts Tables:

Go to your App/Post.php and create a relationship between Posts and Categories Tables:

Query scope with relationship

Here we can use query scope with relationship as following:

Laravel 8 Try Catch in Controller Tutorial Example

In this How to Use try catch In laravel Example TutorialI will show you How to Use try catch In laravel.In this tutorial you will learn to use try catch exception handling in laravel framework. While working or developing application with Laravel framework, you may encounter many errors. It is very important to handle these errors properly in order to build safe and error free laravel application. In laravel you can use try catch statement for proper error handling in laravel.

Laravel 8 Try Catch in Controller Tutorial Example

Below is the syntax that represents the try..catch statement:


The try…catch statement is used to handle the errors.

Find Product By Title

Let’s take a look example of laravel try catch. Here you have product table and find the product with it’s title. So you have the following method in controller to find product by it’s title:

With try…catch we have implemented error handling in the above example code. Now if there is no error we can directly pass product data to blade file. But if there is error we can pass errors to blade file. If you want to display an error in Blade file, you can do look like:


Note:- DO remember to set APP_DEBUG=false in .env file.

Laravel 8 Link Storage Folder Example

In this Laravel 8 Link Storage Folder Example tutorial, I will show you how to link storage folder and access file from there in laravel 8. In this tutorial you will learn to link storage folder and access files from storage folder in laravel 8 application. In this Laravel 8 link storage folder example will cover the following topics:

laravel storage_path

Use the following command to link storage folder in laravel:

The above command creates a symbolic link from public/storage to storage/app/public for you. Now any file in /storage/app/public can be accessed via a link like:

Now, If you get laravel storage link permission denied error then you need to give permission for linking public storage directory in laravel 8. You may also missing a view directories in laravel_root/storage/. In order to fix this, follow given commands:

If you cannot create symbolic links there is an option to have a special route One who reads and provides the image.



Now you can access your files the same way you do a symlink: