Category Archives: Laravel

Laravel Tutorials

How to Increase Column Size using Laravel Migration

In this tutorial, we will learn how to change column length using laravel migration. It is easy to change column length using laravel migration. We will use laravel migration to change column length.

Create Table Migration

Change Column Length using Migration

Now, we will change title string length 50 to 100. We will use laravel migration to change column length. We will following composer package before creating change column length migration:

Install Composer Package

Change Column Length Migration

Laravel Custom Logout Example

In this article, we will learn to create laravel custom logout in your laravel project. It is easy to create laravel custom logout.

Create Laravel Custom Logout

Follow step by step laravel custom logout tutorial to create custom logout in laravel.

Create Route

Let’s open web.php file add the following route to it:

routes/web.php

Create a UserController Controller

Now, create a User Controller Controller name UserController. Use the below command to create controller.

Once the above command executed, it will create a resource controller file “UserController.php” in “app/Http/Controllers/” directory. Go to “UserController.php” and put the following code in it.

app/Http/Controllers/UserController.php

Create a User Blade File

In this step, we will create a view file named user.blade.php inside “resources/views/” directory and put the following code inside it –

resources/views/user.blade.php

Now we have created custom user logout functionality, restart the development server using following artisan command –

and visit the following URL in browser to see custom logout feature:

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