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 API Token Authentication

If you want to create a simple REST API, secured by web tokens for your mobile application or angular based application, you could develop it with Laravel, with very simple steps. In Laravel 5.2, Taylor Otwell introduced TokenGuard class which allows you to authenticate users with tokens. In order to access the protected routes, you […]

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 Role Based Access Control using Middlewares

In this post, I would like to show you very simple approach to develop a security layer around Laravel routes with custom Middleware. Laravel Middleware Middleware provides a convenient mechanism for filtering HTTP requests entering your application. middleware are series of “layers” where HTTP requests must pass through before they hit your application. Each layer […]

Categories
Laravel

Custom Facade in Laravel?

In Laravel world, a facade is a class that provides access to an object from the container. Laravel “facades” serve as “static proxies” to underlying classes in the service container, providing the benefit of expressive syntax while maintaining more testability and flexibility than traditional static methods. When you make a call to a Facade, the […]

Categories
Laravel

Laravel 5.2 – Implicit model binding

Laravel’s route model binding has been around for a while, but Laravel 5.2 is about to make it even easier with Implicit model binding. Implicit model binding makes it painless to inject relevant models directly into your routes and controllers. Implicit model binding gives the benefits of route model binding without having to define anything […]