Category Archives: Laravel

Laravel Tutorials

Laravel 8 Send Email with PDF Attachment Tutorial

In this Laravel 8 Send Email with PDF Attachment Tutorial I will show you how to send email with pdf attachment in laravel 8 application. In this tutorial you will learn to send email with pdf attachment in laravel. In this example we will be using niklasravnsborg/laravel-pdf package to generate pdf file to send as email attachment in laravel 8. We will also learn to generate pdf file using generate pdf library in laravel. In laravel mail class is used to send email. So, we would like to show you send an email in laravel 8. As well as we will also learn to send email in laravel 8 application using a mailable.

Laravel 8 Send Email with PDF Attachment Tutorial

In this step by step tutorial I will demonstrate you with example to send email with pdf attachment in laravel. Please follow the instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Configuration SMTP in .env
  • Step 3 – Install PDF Library
  • Step 4 – Add Email Send Route
  • Step 5 – Create Directory And Blade View
  • Step 6 – Create Email Controller
  • 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 – Configuration SMTP in .env

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 .env file.

Step 3 – Install PDF Library

In this step we will install a pdf library in laravel to send pdf file as email attahcment. we will install niklasravnsborg/laravel-pdf Package via the composer dependency manager. Use the following command to install niklasravnsborg/laravel-pdf Package.

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

config/app.php

Now, execute the following command to publish package’s config file to your config directory by using following command:

Step 4 – Add Send Email 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 Directory And Blade View

In this step, we will create a directory name test inside resources/views directory. Then create an test.blade.php blade view file inside resources/views/ directory. And put the following code into it:

Step 6 – Create Send Email Controller

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

Then go to app/Http/Controllers directory and open SendEmailController.php. Then put the following code into it:

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 Custom 404 500 Error Page Example

In this Laravel 8 Custom 404, 500 Error Page Example tutorial I’ll show you how to create custom 404 and 500 error page in laravel. In this tutorial you will learn to create custom error page in laravel 8. In this step by step tutorial I’ll demonstrate the process to create custom 404 and 500 error page in laravel 8.

Laravel 8 Custom 404 500 Error Page Example

In this tutorial we will be creating custom error page for 404 and 500 error. Please Follow the instruction given below to create custom 404, 500 error pages in laravel:

Custom Error Pages in Laravel 8

Create 404 View File
Create 500 View File
Modify Exceptions Handler

1: Create 404 View File

In this step we will be creating custom 404 error page. Lets go to resources/views directory and create a folder named errors. Then inside the errors folder, we will create a file called 404.blade.php.

resources/views/errors/404.blade.php

2: Create 500 View File

In this step we will be creating custom 500 error page. Lets Go to resources/views directory and create a folder named errors. Then inside the errors folder, we will create a file called 500.blade.php.

resources/views/errors/500.blade.php

3: Modify Exceptions Handler

Now, navigate to app/Exceptions and open Handler.php file and find the render() method. Then modify the render() method only as follow:


as well as render 500 error page in this file as follow:

Laravel 8 Send Mail For Error Exceptions Tutorial With Example

In this Laravel 8 Send Error Exceptions on Mail/Email tutorial I will show you how to send error exceptions on email in laravel 8. In this tutorial you will learn to send error exceptions on email in laravel. Here you will learn to send error exceptions on developer mail or as you want any other mail. In laravel most of error exceptions came for your laravel app. The app will be down and the user will leave your application. In Laravel, all exceptions are handled by the App\Exceptions\Handler class. This class contains two methods: report and render.

Laravel 8 Send Mail For Error Exceptions Tutorial With Example

We are going to show you how you can send error exception mail in your laravel app. Just follow the few steps and it has finished.

  • Create Mail Class
  • Create an Email View
  • Send Error Exception Mail

Create Mail Class

This will create a class ExceptionMail in the app/Maildirectory.

Create Email View

Now, we have to create new view file inside the emails folder that file name email_exception.blade.php. and put the following code in and add your email_exception.blade.php file:

Send Error Exception Mail

Now, go to App\Exceptions\Handler file and put the following code in it:

Now, any error exception is thrown by your application. You will notified via an email with full error exception detail.

Laravel 8 User Activity Log Tutorial

In this Laravel 8 User Activity Log Tutorial I will show you how to create user activity log in laravel 8 application. In this tutorial you will learn to create user activity log in laravel 8 application. You will also learn to delete user activity log in laravel 8 application. In this article we will be using haruncpi/laravel-user-activity log package for creating user activity log in laravel application. We will also be using boostrap ui and auth package for login, register, logout, reset password, forget password, email verification, two-factor authentication, session management.

Laravel 8 User Activity Log Tutorial

In this step by step tutorial to create user activity log in laravel 8 we will be using haruncpi/laravel-user-activity log package. Please follow instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Database Configuration
  • Step 3 – Install Laravel UI
  • Step 4 – Install Bootstrap Auth Scaffolding
  • Step 5 – Install Npm Packages
  • Step 6 – Install And Configure User Activity Log Package
  • Step 7 – Run PHP artisan Migrate
  • 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 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 – Install Laravel UI

In this step we will now install laravel UI package using following command:

Step 4 – Install Bootstrap Auth Scaffolding

Now, we will install auth scaffolding bootstrap package in laravel app by using the following command:

Step 5 – Install Npm Packages

In this step we will install npm dependencies using following command:

Then type the following command on cmd to run npm:

Step 6 – Install And Configure User Activity Log Package

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

After that, visit app/models directory and open user.php model and add the following line of code into it:

Step 7 – Run php artisan Migrate

Now, run following command to migrate database schema.

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 Set Up File Permissions in Laravel 8

In this How to Set Up File Permissions in Laravel 8  tutorial I will show you how to set file permission or directory permission in laravel 8 application. In this tutorial you will learn to set file permission in laravel, you will also learn to set directory permission in laravel 8.

When we create a new laravel 8 application we may encounter some errors related due to file permission in laravel. Below is list of some of common issues we may encounter:

  • How to fix Error: laravel.log could not be opened Permission denied?
  • How to set up file permissions for Laravel?
  • Laravel – bootstrap/cache/services.php missing
  • Laravel – bootstrap/cache directory must be present and writable
  • Laravel – bootstrap/frameworks/sessions.php, views.php, services.php missing
  • failed to clear cache. make sure you have the appropriate permissions

How to Set Up File Permissions in Laravel 8

In this step by step tutorial I will help you to fix some of common issues related to files permission in laravel.

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 – Start Development Server

Now, lets start the development server using following artisan command –

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

Solution 1 – Server Error 500 when accessing Laravel 8 (Solve)

After fresh laravel 8 installation we get  server error 500 when we accessing project root . So, you can try to run the following command on terminal. You may also need to adjust the permissions of storage and bootstrap/cache.

Solution 2 – laravel.log could not be opened?

If you now face Laravel failed to open stream permission denied storage error. Now I will show you how to solve storage/logs/laravel.log” could not be opened: failed to open stream: permission denied. It turns out I was missing a view directories in laravel_root/storage/. In order to fix this, all I had to do was:

Then, You need to adjust the permissions of storage and bootstrap/cache.

Solution 3 – Laravel – bootstrap/cache/cache.php, sessions.php, views.php, services.php missing

Create these directories if they don’t exist in laravel:

Then

Try to set correct permissions to the storage folder: chmod -R 775 storage/

Laravel 8 Livewire Form Wizard Tutorial

In this Laravel 8 Livewire Form Wizard Tutorial I will show you how to create multi step form or form wizard using livewire package in laravel 8 application. In this tutorial we will learn to create multi step form or form wizard in laravel using livewire package. In this article we will be creating simple multi step form wizard with bootstrap wizard design using livewire package. In this tutorial you will also learn to install, setup and use laravel livewire form.

Laravel 8 Livewire Form Wizard Tutorial

In this step by step livewire form wizard tutorial will guide you through how to create multi-step form or form wizard using livewire package in laravel 8. Please follow instruction given below:

  • Step 1: Install Laravel 8 App
  • Step 2: Connecting App to Database
  • Step 3: Create Model & Migration For File using Artisan
  • Step 4: Install Livewire Package
  • Step 5: Create Form Wizard Components using Artisan
  • Step 6: Add Route For Livewire Form Wizard
  • Step 7: Create View 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: Create Model & Migration For File using Artisan

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

The above command will create a model name Product.php and also create a migration that name create_products_table.php. Now, go to database/migrations folder and open create_products_table.php file. Then put the following code into create_products_table.php file:

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

Now, Open App/Models/Product.php file and add the fillable properties:

Step 4: 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 5: Create Form Wizard Components using Artisan

In this step we will create a form wizard component using following artisan command:

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

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


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

Step 6: Add Route For Livewire Form Wizard

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

In this step we will create blade view file. Go to resources/views/ folder and open welcome.blade.php file. Then add the following code into your welcome.blade.php file:

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 Authentication with Breeze Tutorial Example

In this Laravel 8 Authentication with Breeze Tutorial Example I will show how to install and use breeze authentication in laravel 8 application. In this tutorial you will learn to install and use breeze authentication in laravel 8. In this example we will be using breeze auth to implement user authentication in laravel application. The breeze auth will be used to create login, register, reset the password, forget password, email verification, and two-factor authentication blade views and controller file. The laravel 8 breeze auth create simple and lightweight authentication scaffolding.

Laravel 8 Authentication with Breeze Tutorial Example

In this step by step tutorial I will demonstrate you with example to implement user authentication using breeze authentication in laravel 8 application. Please follow instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Install breeze Auth Scaffolding
  • Step 4 – Run PHP artisan Migrate
  • Step 5 – Install Npm Packages
  • Step 6 – 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 breeze Auth Scaffolding

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

Now you have to install laravel breeze for simple auth scaffolding. so let’s run bellow command:

Step 4 – Run php artisan Migrate

Now, run following command to migrate database schema.

Step 5 – Install Npm Packages

Now run following command to install node js and npm dependencies:

Then type the following command on cmd to run npm:

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 Backup Store On Google Drive Example

In this Laravel 8 Backup Store On Google Drive Example I will show you how to take laravel site backup in google drive. In this tutorial I will also show you how to integrate google drive in laravel 8 to store backup on google drive. In this example we will learn Google Drive integration in Laravel 8. In this example we will be using spatie/laravel-backup package to take backup in google drive.

Laravel 8 Backup Store On Google Drive Example

In this step by step Laravel 8 Backup Store On Google Drive Example I will demonstrate you how to integrate google drive in laravel site to take site backup. Please follow instructions given below:

  • Step 1 – Setup Google Drive Account
  • Step 2 – Install Laravel 8 App
  • Step 3 – Connecting App to Database
  • Step 4 – Install spatie/laravel-backup
  • Step 5 – Setup Google Drive as Filesystem in Laravel
  • Step 6 – Configure Google Drive Details
  • Step 7 – Execute Backup Command

Step 1 – Setup Google Drive Account

Before integrating Google Drive in laravel 8. that you have google client id and secret id,  refresh token and folder id. Please follow the instruction given below. You can create Google App in Google Developer Console by following the steps given below.

Step 1 – Visit the link given below and create a new project:

Step 2 – Visit “Library” of google search console and search for “Google Drive API“:

Step 3 – Then enable the Google Drive API.

Step 4 – Now, Visit “Credentials” and click on the tab “OAuth Consent Screen”. Here you will get options to select user type, select “External” option, and click the “CREATE” button.

Step 5 – Please provide following details like “App Name“, “User support email” and “Email” in the Developer contact information and click Save And Continue button. For other forms “Scopes“, “Test Users” and “Summary” click on Save And Continue button and go to the dashboard. Don’t worry about the other fields.

Step 6 – Now, on OAuth consent screen, you will see that the App’s Publishing status is testing. Click the Publish App button and confirm.

Step 7 – Now, visit Credentials and click the button that says “Create Credentials” and select “OAuth Client ID“.

Step 8 – For “Application type” choose “Web Application” and give it a name. You also need to provide your “Authorized redirect URIs”.

Step 9 – Now visit the below link:

In the top right corner, click the settings icon, check “Use your own OAuth credentials” and paste your Client ID and Client Secret.

Step 10 – on the left, scroll to “Drive API v3”, expand it, and check each of the scopes. Click “Authorize APIs” and allow access to your account when prompted.

Step 11 – You also need to check “Auto-refresh the token before it expires” and click “Exchange authorization code for tokens“.

Step 12 – Now, complete this step and click on step 1 again and you should see your refresh token.

Step 13 – Now you need folder ID that is optional. If you set folder ID to null, in that case, it is going to store backup files in the root path of Google Drive. You can get the folder ID from the URL.

Step 2 – 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 3 – 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 4 – Install spatie/laravel-backup

In this step run the following command to install spatie/laravel-backup package in laravel 8:

Now, run the following command to publish this installed package:

Now, you need to add google in the disk option in the config/backup.php.

Step 5 – Setup Google Drive as Filesystem in Laravel

Now, you need to run the following command to install a Filesystem adapter for Google drive:

Now, inside the boot() method add the Google driver for the Laravel filesystem:

app/Providers/GoogleDriveServiceProvider.php

Now, you need to register the service provider toproviders array of config/app.php.

Step 6 – Configure Google Drive Details

In this step, you need to configure Google drive app with this laravel app. Go to the config directory and open filesystem.php file and add the client id, secret and callback url:

You also you need to update .env file of laravel 8 app. Please add the following Google drive credentials:

Step 7 – Execute Backup Command

In this step we are ready to take backup run the following command to check the backup file is created or not:

Laravel 8 Backup Store On DropBOX Tutorial

In this Laravel 8 Backup Store On DropBox tutorial I will show you how to take laravel site backup in DropBox. In this tutorial I will also show you how to integrate DropBox in laravel 8 to store backup on DropBox. In this example we will learn DropBox integration in Laravel 8. In this example we will be using spatie/laravel-backup package to take backup in DropBox.

Laravel 8 Backup Store On DropBOX Tutorial

In this step by step Laravel 8 Backup Store On DropBox Example I will demonstrate you how to integrate DropBox in laravel site to take site backup. Please follow instructions given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Install spatie/laravel-backup
  • Step 4 – Setup Dropbox as Filesystem in Laravel
  • Step 5 – Configure Dropbox Details
  • Step 6 – Execute Backup Command
  • Step 7 – Conclusion

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 spatie/laravel-backup

In this step run the following command to install spatie/laravel-backup package in laravel 8:

Now, run the following command to publish this installed package:

Now, you need to add dropbox details in the disk option in the config/backup.php.

Step 4 – Setup Dropbox as Filesystem in Laravel

Now, you need to run the following command to install a Filesystem adapter for DropBox:

Then, inside the boot() method add the Dropbox for the Laravel filesystem:


After this, register the service provider by adding the following line in the providers array of config/app.php.

Step 5 – Configure Dropbox Details

Now you need to configure Dropbox app with this laravel app. Go to the config directory and open filesystem.php file and add the client id, secret and callback url:


And also you need to update .env file of laravel 8 app. In this environment file you need to add the following Dropbox auth token:

Step 6 – Execute Backup Command

In this step we are ready to take backup run the following command to check the backup file is created or not:

Laravel 8 Compare Two Carbon Dates

In this Laravel 8 compare two carbon date tutorial I will show you how to compare two dates in laravel 8 with carbon. In this tutorial you will learn to compare two carbon dates in laravel 8. In this example we will be using carbon dates. The Carbon is simple PHP API extension for DateTime and supported by Laravel version 6/7/8. In this article I will share various example to compare dates in laravel.

Laravel 8 Compare Two Carbon Dates

In this step by step tutorial I will demonstrate you with example on how to compare two date in laravel.

How to Compare Two Dates in Laravel Carbon?

Below is list of functions to check compare date using carbon in laravel. Carbon function helps you to find which date is bigger, smaller or equals from two dates in laravel:

  • eq() equals
  • ne() not equals
  • gt() greater than
  • gte() greater than or equals
  • lt() less than
  • lte() less than or equals

1 – Laravel Carbon eq() equals

The carbon eq() function is to check given date is equal or not.

2 – Laravel Carbon ne() not equals

The carbon ne() function is to check given date is not equal or equal.

3 – Laravel Carbon gt() greater than

The carbon gt() function is to check given date greater or not.

4 – Laravel Carbon gte() greater than or equals

The carbon gte() function is to check given date is greater than or equal.

5 – Laravel Carbon lt() less than

The carbon gte() function is to check given date is lesser than or not.

6 – Laravel Carbon lte() less than or equals

The carbon gte() function is to check given date is lesser than or equal.

Laravel 8 Convert PDF to Image Tutorial Example

In this Laravel 8 Convert PDF to Image Tutorial Example tutorial I will show you how to convert pdf to image file in laravel. In this tutorial you will learn to generate or convert a pdf file to image in laravel. In this example we will be using php imagick package to convert pdf to image. In this article I will show you how to install and use imagick to convert pdf to image file. You will also learn to install imagick with laravel. Before starting with this tutorial you are required to install imagick package and to enable imagick package in apache web server.

Laravel 8 Convert PDF to Image Tutorial Example

Use the following steps to convert pdf to image in laravel 8 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: Installing Imagick PHP Extension And Configuration

Now in this step we will install imagick library in server using following command:

Now, run following command to check the list the version available from the Ubuntu repositories using the apt list command.

The -a flag tells apt to list all version of a package available from the repositories. The output will look similar to the following, and at the time of this writing, there was only a single version available.

After this you are required to restart Apache web server:

Verify Installation

Run the following command to verify the imagick library installation:

If the installation was successful, the output of the command will simply show one line, and it will only contain the name of the module imagick.

You can also verify installation with phpinfo() method. Or execute the following command

Which will output the following information, where the modules status is shown as enabled.

Alternatively, by adding the phpinfo() function to a php script, and then accessing the script from a web browser. Now, you are able to see the module is installed and enabled.

After some authorization change in fowling the path

/etc/ImageMagick-6/policy.xml

To Convert

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 3: Create Controller

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

And put the following code into 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 –

Laravel 8 Get Country, City Name & Address From IP Address Example

In this Laravel 8 get country name, country code, city name, and address from user IP address example tutorial I will show you how to get country name, country code, city name, and address from user IP address in laravel 8. In this tutorial you will learn to get country name, country code, city name, and address from user IP address in laravel 8. When you working on web development project you come to situation where you may want to fetch user information such as country Name, country Code, region Code, region Name, city Name, zip Code, iso Code, postal Code, latitude, longitude, metro Code, metro Code from ip address in laravel 8. In this example I will help you to fetch user info from IP their ip address. We will be using stevebauman/location package in this example to fetch country name, country code, city name, and address from IP address.

Laravel 8 Get Country, City Name & Address From IP Address Example

In this step by step tutorial I will demonstrate you with example to fetch country name, country code, city name, and address from IP address. Please follow the instruction given below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Connecting App to Database
  • Step 3 – Install “stevebauman/location”
  • Step 4 – Add Routes
  • Step 5 – Create Controller By Command
  • Step 6 – Start 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 “stevebauman/location”

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

Then, Go to config directory and open app.php file. And register this package into laravel 8 app by adding the following code into your app.php file:

Now you need to run the following command on terminal to publish config/location.php file:

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 GeoLocationController using command given below –

Now, go to app\Http\Controllers and open GeoLocationController.php file. Then put the following code into your GeoLocationController.php file:

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