Category Archives: Blog

Blog

Laravel Custom Env. Variables

In this tutorial, I’ll show you how to create Custom Env. Variables in laravel 8. In this example we will create custom laravel environment variable.

Laravel Custom Env. Variables

In this step by step laravel custom environment variable tutorial, we will learn to add custom env. variable in our laravel application.

using env() helper

.env

using config() helper

config/google.php

 

wer

How To Add Default Value of Column in Laravel Migration

In this article, I’ll show you how to add default column value in laravel migration. You will learn learn to set defaule value of column while creating table using laravel migration.

How To Add Default Value of Column in Laravel Migration

Laravel migration provide default() and nullable() method to set default value of a column. In this example we will learn how to add default value as null, boolean, current time etc. In this step by step we will set default value of table column using migration in laravel.

Create Table Migration

Use the following artisan command to create table migration:

After the command executed you will notice a migration file created. Open migration file and put the following code in it:

database/migrations/YYYY_MM_DD_TIMESTAMP_create_products_table.php

1) Laravel Migration Default Value Null:

2) Laravel Migration Default Value Boolean:

3) Laravel Migration Default Value Current Date:

4) Laravel Migration Default Value with Update:

Laravel class ‘memcached’ not found

I have onfigured memcached as driver but I am getting following error “laravel class ‘memcached’ not found”. So, I have figured out a solution to share with you.

In this tutorial laravel class ‘memcached’ not found, I’ll show you how to fix the laravel class ‘memcached’ not found error.

Install Memcached in Server

in this step we will install memcached in ubuntu server and php extension for it.

Install Memcached Extension

Now, you need to install php extension for memcached. Please verify it’s version with your php version.

I hope this will fix the laravel class ‘memcached’ not found error.

How to Remove Package In Laravel

In this tutorial, I’ll show you how to remove package in laravel.In laravel it is easy to remove uninstall or remove a laravel package.

How to Remove Package In Laravel

In this example, we have already installed the yajra/laravel-datatables-oracle package in our laravel project. Now we will remove yajra/laravel-datatables-oracle package from our laravel project. Please follow this step by step instruction to uninstall or remove laravel package.

Step 1:-

First of all Remove the providers declaration from the config/app.php file

Step 2:-

Now, you need to remove aliases from config/app.php file.

Step 3:-

Next, you have to remove package references from your Controllers, Models, Routes, or any other file.

Step 4:-

If you have published any vendor-related files then manually delete them.

Step 5:-

Run following command with your vendor and package name to remove the package from the vendor folder:

Example:-

Linux Shell Script For Database Backup

In this tutorial, I’ll show you how to backup database using shell script linux. We will learn with the help of example of linux shell script for database backup. In this example, I just created a MySQL shell script that I use on my Linux servers to make database backups with mysqldump.

Linux Shell Script For Database Backup

Create .sh File

In this step, We will create a database_backup directory in server home directory. Now we will create a hell script file backup.sh in database_backup folder. Let’s open backup.sh file and put the following code in it.

/home/database_backup/backup.sh

Executable .sh File

Setup Crontab

In the last step, we will setup a cron job for backup.sh file in crontab. Let’s open crontab file using below command:

Add below line in crontab file to run the shell script to take laravel database backup.

Remove index.php from the URL in Laravel

In this article, I’ll show you how to remove index.php from the URL in your laravel application. if you notice in your laravel application you have to access links like:

In this tutorial, i will share a solution with you to remove index.php from URL of your laravel application.

Remove index.php from the URL in Laravel

if you want remove index.php from URL in laravel application then just open following file and make the changes below:

Create Route

Now, open your route file and add following route to it.

routes/web.php

now if you open url like bellow then:

will redirect to:

How to Http Curl Delete Request in Laravel

In this articel, I’ll show you how to http curl delete request in laravel. It is easy to make http curl delete request in laravel.

How to Http Curl Delete Request in Laravel

In this step by step we will learn how to make curl delete request in laravel. In this example we will be using laravel GuzzleHttp package.

Install guzzlehttp/guzzle Package

First, we have to install guzzlehttp/guzzle composer package in our laravel project. Switch your project directly in command prompt and use the following composer command to install laravel guzzlehttp/guzzle composer package in your project:

Example:-

Example:-

Output:-

Example:-

Output:-

Laravel 8 How To Install Font Awesome Icons Example

In this article, I’ll show you how to install font awesome in laravel application. In this example we will learn how to use font awesome icons in laravel. We will use laravel mix add font awesome.

Laravel 8 How To Install Font Awesome Icons Example

In this tutorial I’ll give example of how to install font awesome in laravel. In this example, i will guide you step by step how to install font awesome icons in laravel mix. We will use two example of installing font awesome in laravel. one will be using npm command using laravel mix and another example will using cdn js.

Laravel 8 Install Font Awesome Icons using Npm

Step 1:-

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.

Step 2:-

Now, we need to install npm in our new laravel application.Now, use the following command  this will create “mode_modules” folder in your root directory and store all npm module.

Step 3:-

Now, we are ready to install font awesome library using bellow npm command.

Now we are ready to run npm dev command,

Now we are ready to use generated app.css file in our blade file as bellow:

resources/views/welcome.blade.php

Laravel 8 Install Font Awesome Icons Using CDN

In this example, we will use cdn js file for adding font awesome icons, so let see bellow file code:

resources/views/welcome.blade.php

Store Log Of Eloquent SQL Queries In Laravel 8

In this article, I’ll show you how to Store Log of Eloquent SQL Queries In Laravel 8. In this step by step tutorial I’ll explain laravel 8 Store Log of Eloquent SQL Queries. I’ll also show you to Store Log of Eloquent SQL Queries In Laravel.

Store Log Of Eloquent SQL Queries In Laravel 8

Developing a laravel application you come to situations where you  may require to log SQL Query. Logging of SQL Queries helps to debug errors and make development easy.

Store In Default Log File

In Laravel, there is default log file located at storage/logs/laravel.log. In this example we will be going to store SQL log in laravel’s default log file. Let’s open AppServiceProvider.php file from app/Providers folder and put this code to boot() method:

app/Providers/AppServiceProvider.php

Laravel 8 Create A Custom Log File

We can also create a custom log file to store log data. In this example we will be creating a custom log file. Create query.log file in the storage/logs folder. In the boot() method of AppServiceProvider.php file put the following code:

app/Providers/AppServiceProvider.php

storage/logs

Laravel 8 How To Handle “No Query Results For Model” Error

In this article, I’ll show you how to solve “No Query Results For Model” Error.

Working with restful API in my laravel project with User model I came across following error on show method: “No query results for the model [App\\User] 1”.  After lots of effort I came to solution to handle “No Query Results For Model” Error.

Laravel 8 How To Handle “No Query Results For Model” Error

In this article I would like share solution for Handle “No Query Results For Model” Error.

Controller Method :-

In this code I am facing error:

I handle this error as following:

Handle Exception : app/Exceptions/Handler.php

Laravel Pluck Method Example

In this laravel pluck method tutorial, I’ll show you how to use laravel eloquent pluck() method. In this tutorial I’ll demonstrate the use of laravel pluck method.

Laravel Pluck Method Example

The laravel eloquent pluck() method is used to extract specified values from array or given collection.

Example:-

In this laravel pluck method tutorial we will use following collection for example:

Let suppose now we want to extract only the cities of the users. This can be achieved using  laravel pluck method as following:

Extract Single Value From Collection Using Pluck()

Let suppose now we want to extract only the single value from the collection using pluck() method. This can be achieved using  laravel pluck method as following:

Extract Multiple Value From Collection Using Pluck() in Laravel

Let suppose now we want to extract only the multiple value from the collection using pluck() method. This can be achieved using  laravel pluck method as following:

Laravel Pluck Relationship

Let suppose now we want to extract values from the collection with relationship objects using pluck() method. This can be achieved using  laravel pluck method as following:

Laravel Cookies Get, Set, Delete Cookies

In this tutorial, I’ll show you how to use cookies in laravel application. You will learn to Set, Get, and Delete Cookies in laravel.You will also learn how to check cookies exist or not.

what is cookies?

Cookies are a small data file, which is stored in the browser. Cookies are used for tracking/identifying user’s interaction with application. Cookies are mainly used to store user specific data.

Laravel Cookies Get, Set, Delete Cookies

In this tutorial, I’ll demonstrate you how to Get, Set, Delete Cookies in laravel.

Laravel Set Cookies

The cookies::make() method to create or set cookies in laravel:

Using the cookies::forever method(), you can set cookies forever:

Laravel Get Cookies

The cookie::get() method is used to get cookies in laravel:

If you want to get all cookies in laravel, you can use cookie::get() method as following:

Laravel Delete Cookies

The cookie::forget() method is used to delete cookies in laravel:

The Cookie::has() method is used to check cookie exists or not. If you want to check if cookie exists or not.

Add Cookies With Response

Sometime, you may want to add cookies in laravel response. So you can add cookies with response in laravel as following: