Archive

March 2018

Browsing

Laravel 5 get client IP address – Many times we have to store the client IP address. In my project I working on rating functionality. I need to store the IP address to avoid repeating rating. We can easily get client IP address using Laravel 5. When we are using PHP we get client IP address using $_SERVER. Laravel 5 provides a very easy way to Laravel get IP address.

Laravel 5 get client IP address

Finally, We are going to learn Larave get IP address. We can get client IP address using Laravel Facades and Helpers like

You can use any method for getting the client IP address. If you face any issue with getting IP address write the comment below. We always most welcome for suggestion or improvements write the comment.

Today, We are going to learn Laravel print validations error messages on blade file. All Laravel application use Validation library So, every time we need to print error messages on blade view file. Let’s see how we can print the all laravel validation messages.

Laravel print validations error messages

Normally We are using the validation library with the form like create, edit, contact page. So, let’s see how we can print validations error messages like

The validation error message will work with the Laravel validation library. When we write the validation on the controller like

Then Laravel checks all the incoming request. If incoming request does not match with all conditions. Then Laravel auto redirects a user to the previous page with the validation messages.

Finally, We are ready to Laravel print validations error messages to blade file.

When I am starting new Laravel project I get an error “laravel 5 Class Input not found”. When I am going to find the solution for this error. What I see Laravel remove Input aliases from “config/app.php” file. So, If you are using Laravel 5.2 or greater version Alos, you can get this error when you are trying to use Input Class.

laravel 5 Class Input not found

Here you can check the Laravel commit to remove Input facade definition from “config/app.php”. Hence you have to manually add that to aliases array like

Also, You can import Input Facades directly from Controller as required.

Finally, We are ready for Input class. Still, If you face any issue write the comment below.

Laravel 5.6 CRUD tutorial In this tutorial We will cover Laravel Listing, create, update, delete the basic application functionality. All Laravel application must have Larave CRUD tutorial functionality.  I will teach you how to create Laravel CRUD step by step. This tutorial is useful for Laravel beginner. Because In this tutorial I will cover all basic concept of Laravel for starting an application.

There are many Laravel CRUD generator tutorial but it is not meaning for the beginners. So, For the Beginners user, I am creating this Laravel CRUD Tutorial.

Today, We are going to learn Laravel 5.6 CRUD tutorial step by step. First of all, We are starting from going to install Laravel application.

Laravel 5.6 CRUD tutorial

We will follow the steps of the creating the Laravel 5.6 CRUD tutorial

  1. Laravel installation
  2. Database configuration
  3. Integrate AdminLte theme
  4. Write the Routes
  5. Generate migration files
  6. Create the Model
  7. Generate Controller
  8. Create the Views files

Finally, We are ready with the steps we will follow these steps for creating CRUD Tutorial.

We are going to create the category module for CRUD tutorial. Let’s start the CRUD tutorial

1 ) Laravel installation

First of all, We are going to install Laravel using composer by following the command

Follow this tutorial for installing Laravel and getting more detail about Laravel Installation.

Finally, We are ready with the Laravel Application. Now, We are going to configure Database.

2 ) Database configuration

After, Creating the  Laravel project open the configuration file “.env” then change the database configuration like

Next, We are going to run migration for generating Laravel tables

If you getting an error by following migration command like “1071 specified key was too long” then just follow this tutorial.

Finally, We are ready with the Database configuration. Now, We are going to integrate AdminLTE theme.

3 ) Integrate AdminLte theme

Finally, We are going to integrate AdminLTE theme, But I create the different tutorial for integrating AdminLTE admin theme. Because I want to make this tutorial simple and sort. So, Please follow this tutorial for integrate AdminLTE theme.

Before, Going to the next step make sure the AdminLTE theme is install properly.

4 ) Write the Routes

Finally, We are ready with the Laravel application with admin theme. Now, First of all, We are going to create the routes for our CRUD tutorial. Let’s open the routes/web.php file.

We will create the route group for all admin module URL are located on the same prefix “admin”. Also, We have namespace “Admin”. So, our Controller files are stored in the Admin folder.

5 ) Generate migration files

Now, Let’s create the migration for the category table. We have to create the category table for storing the data in a database. We generate migration file using artisan command like

After, Follow this command the Laravel generate migration for the category table. Laravel generate migration file at database/migrations/ You will see the new migration file for a category on migrations folder. Let’s open the category migration file and change the code like

Finally, We are ready with the migration table. So, Let’s run the migration first by the following command

The migrate command will create the category table into the database. So, We are ready with the category table. Now, we are going to create the Controller.

6 ) Create the Model

Finally, We are ready with the category table. Now, let’s create the Model file for the category table by following the command.

So, Laravel generates Model file inside app folder. You will find the category model file at app/Category.php  let’s open the model file then write the code like

Finally, We are ready for the Category Model. So, We are going for creating the controller file.

 7 ) Generate Controller

We are going to creating the CategoryController file. As per describe on a route. We are using the namespace Admin on the route group. So, We have to create the Controller file inside the Admin folder like “App\Http\Controllers\Admin”. So, Let’s create the Category Controller by the following command

Finally, We are ready with the Category Controller. So, Open the controller and write the code like

Finally, We are with the Category Controller. Now, We able to perform the insert, update, delete operation using category controller.

8 ) Create the Views files

Now, We are going for creating the view files. Laravel use blade template for the view file. We can create the user interface using view file. We are going to create three view files for insert, create, update.

  1. index.blade.php
  2. create.blade.php
  3. edit.blade.php

Create all those files inside “resources\views\admin\category” folder step by step.

First of all, We are going to creating the listing. So, let’s open the “resources\views\admin\category\index.blade.php” file and write the code like

Now, we are going to create the insert category form. So, let’s open the “resources\views\admin\category\create.blade.php” file and write the code like

Now, we are going to create the update category form. So, let’s open the “resources\views\admin\category\edit.blade.php” file and write the code like

We are ready with the Laravel CRUD tutorial. Now we can run the Laravel application and check the CRUD example. Follow the command for running laravel application.

Now, check the category module using this URL.

The output something look like

Laravel Crud

I hope this Laravel 5.6 CRUD tutorial is helpful for you. We are creating the reusable Laravel CRUD Code. you can reuse the module by just changing some labels on Controller file. If you face any issue by following this tutorial please write the comment below.

 

Today, I am going to tell you about the “Laravel Call undefined method lists Illuminate\Database\Query\Builder::lists()” error and going to share solutions with you.

When I am working with Laravel many times I used the eloquent “lists” method for getting the lists of the names like the country name with the ID as the key like.

When I am trying the use the lists method on the laravel 5.3 I am getting the error  “Laravel Call undefined method Illuminate\Database\Query\Builder::lists()” like

Laravel Call undefined method lists

When I search for this error I found that the “lists” method is removed from the Laravel 5.3. Now, we get the same lists data using pluck method form the Laravel 5.3 like

Finally, We are getting the solution use pluck method instead of the lists. Still, if you face any issue write the comment below.

Many web servers don’t allow to send mail directly from the server for the security purpose. So, Today we are going to learn Laravel SMTP send mail using Gmail SMTP. Also, Let’s see how we can send mail using Laravel Gmail SMTP. We can easily set up the SMTP driver for the Laravel application.

First of all, We are going to install Laravel step by step if not installed

Laravel SMTP send mail using Gmail SMTP

Once we are ready with Laravel let’s start the Laravel SMTP setting using Gmail SMTP step by step. Let’s open the “.env” file then follow the instruction

  1. First, we need to change the MAIL_DRIVER to smtp
  2. We need to set up the MAIL_HOST like “smtp.gmail.com” or “mail.domainname.com
  3. We need to set up the MAIL_PORT correct port for TLS and SSL like 587, 445, 25 etc…
  4. provide the username for the authentication MAIL_USERNAME
  5. provide the password for the authentication MAIL_USERNAME
  6. set up the encryption MAIL_ENCRYPTION for the authentication SMTP detail

After, setting up the server detail “.env” look like

Finally, We are ready with the SMTP If you are using Gmail as SMTP server then make sure don’t forget to enable Less Secure app.

Now, let’s check Laravel SMTP is working on not by sending the mail using Laravel like.

Now, let’s create the email template laravelhive.blade.php into the “resources/views/emails” directory.

Finally, We are ready for sending the testing email by following “http://localhost:8000/send-mail” URL.

If you face any issue with sending mail using Laravel SMTP write the comment below.

Today, We are going to learn How to integrate admin theme AdminLTE Laravel. We are using Acacha AdminLte Laravel package As a Laravel Admin panel. Also, AdminLTE is an open source admin panel theme. So, We can easily use AdminLTE with Laravel as an admin panel. Acacha AdminLTE laravel package switch default Laravel scaffolding/boilerplate to an AdminLTE template and Pratt Landing Page with Bootstrap.

First of all, We are going to install Laravel, Follow this tutorial for installing Laravel.

After, Installing the Laravel let’s generate the auth scaffolding and migration using artisan command like

Also, If you face any issue when you run migration like “1071 specified key was too long” just follow this tutorial.
Finally, We are ready with the Fresh laravel installation Now, We are going to install AdminLTE with Laravel.

AdminLTE Laravel 5.6

We are going to install AdminLTE admin theme with Laravel 5.6 using Acacha AadminLTE Laravel Package. First of all, We are going to install Acacha AdminLTE package using composer like

Once the Acacha AdminLTE package is installed  We need to register Service Provider and Aliases to the Laravel application so let’s open the config/app.php file and add Service Provide entry first

Now we are going to register Aliases

After, Register Service Provides and aliases We need to publish Acacha AdminLTE package configuration and assets using artisan command like

Finally, We are ready with the AdminLTE Laravel now let’s run the laravel application by the following command

If you face any issue to Integrate AdminLTE Laravel 5.6 please write the comment. Also, the improvement and suggestions are always welcome please write the comment.

One day I install Laravel 5.6 When I am going to create a migration for the Laravel application. Then I run Laravel migration command I got an error like 1071 specified key was too long max key length is 767 bytes. I find the solution why I got Laravel 1071 specified key was too long error when I run the migration.

Since Laravel 5.4 change the default database character set to “utf8mb4” for includes support for storing emojis. This only affects If you running MariaDB or older versions of MySQL. You may hit this error when you are running migration command.

Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes”)

As per Laravel 5.4.* documentation, You need to set default string length on Boot method for the resolving this issue.

Laravel 5.6 – 1071 specified key was too long

First of all, Open the App Service Provider at “app/Providers/AppServiceProvider.php” then follow below steps.

After, applying that solution everything is working fine. Still, if you face any issue write the command below.

Today, We are going to learn about Laravel clear cache. Laravel create the cache of Route, View, Config file data. When I working on a project suddenly I get a fatal error on Laravel view file. After, Resolving that issue on view file I see the error still exists in the view file. The issue is the Laravel cache my view file. I resolve that issue by clearing Laravel cache. So, I want to share with you How to clear laravel cache.

We can clear Laravel cache using artisan command using two ways.

Laravel Clear cache using Artisan Command

We are going to clear Laravel cache using Artisan command

Reoptimized class loader

Clear Facade Value

Laravel Clear Route Cache

Laravel Clear View Cache

Laravel clear Config Cache

Finally, We are learning Laravel clear cache using artisan command. But how to clear Laravel cache when we are using shared hosting. Because Shared hosting doesn’t provide command line interface. So, Let’s see how we can clear Laravel cache on shared hosting.

Laravel Clear cache in shared hosting server

We are going to learn about Laravel clear cache in shared hosting server by Laravel Route using Artisan Command

Now, You just need to call route URL for clearing cache on shared hosting.