Categories
Laravel

How to get last inserted id in Laravel

In this post, I would like to show the different ways to get last inserted ID from the database table when working with Laravel PHP Framework. In the core PHP, we will get last inserted ID with mysqli_insert_id() or PDO::lastInsertId() methods, but in Laravel framework you don’t need have to use those methods. In the […]

Categories
Laravel

Laravel Create Controller, Model and migration in one Artisan Command

Artisan is the command-line interface included with Laravel. It provides a number of helpful commands that can assist you while you build your application. Here I am gonna show you a command which will generate controller, modal and migration files. As you can see, actually the command is for creating modal but by passing -crm […]

Categories
Laravel

How to record last login time and IP address of a user In Laravel

Recording last login information is useful and you can easily save and update the last login time and IP address of the client. You can achieve this in several ways but I am gonna show you very simple and effective technique, just add the below-shown method to the login Controller – App\Http\Controllers\Auth\LoginController.php If you see […]

Categories
Laravel

How to get Client IP Address in Laravel 5

Sometimes you need to track the IP address of the visitors for different reasons. In this tutorial, I would like to show you, how to get the IP address of clients in Laravel application. In PHP you use super global variable $_SERVER to get ip address but in Laravel you will get ip address by […]

Categories
Laravel

Laravel 5 – SHA1 encryption instead of BCrypt

Recently I have migrated core PHP application to the Laravel5 framework. The old application used SHA1 encryption so I have implemented Hashing contracts of laravel5 to use SHA1 instead of BCrypt. Create Directories in app called “Libraries\ShaHash” and create a file called SHAHasher.php and place below code in it. Then create a service provider class(App\Providers) […]

Categories
Laravel

Laravel 5 – Prevent Browser back button after Logout

In this post, I would like to share a simple Laravel5 Middleware which prevents going back to the previous protected page after Logout by hitting the back button on your Browser. When you hit the browser back button after logout, it will take you to the original page instead of redirecting to login page. It […]

Categories
Laravel

Laravel5 Inactivity idle session logout

In this post, I would like to show how to automatically log out the user after some period of inactivity. Session timeout or Session expire depends on the server configuration so in order to achieve our target we are going to write middleware in the Laravel5. Without making any changes to server configurations we will […]

Categories
Laravel

How to redirect requests to HTTPS in Laravel 5

I know we can achieve same with other methods but I am going do it with the Laravel’s Middleware. So let’s create Middleware called ForceHttpProtocol. How it will work Our ForceHttpProtocol middleware will redirect every request to https if – The current request comes with no security protocol means HTTP and If your environment is […]

Categories
Laravel

How to install Laravel 5

In this post, I am going to share Laravel installation steps. We Can install Laravel by using composer and Laravel installer. Laravel Installer is a new feature which is introduced in Laravel 4.1, which can create a project in a few seconds and is much faster than Composer. NOTE – I assume you have PHP […]

Categories
Laravel

Login Throttling in Laravel 5.1

  Login Throttling is also called rate limiting which is very useful to increase the security of the application by protecting login form. Basically the idea behind login throttling is which will count the number of login attempts and once the user or attacker reaches given 3 or 5 number of failed attempts, we will […]