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

How To Validate Date Format in Laravel

In this post, I would like to show you date format validation in Laravel application, You should always validate forms to ensure that you receive data in the good format. Date validation Rules Here is the list of validation rules date date_format after:date after_or_equal:date before:date before_or_equal:date How to use validation rules You can validate date […]

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

bootstrap 4 carousel with Laravel

Laravel’s Blade templating engine’s @foreach control structure directive has $loop variable which is available inside every @foreach loop. The $loop variable is a stdClass object that provides meta information about the loop you’re currently inside. Take a look at the properties it exposes: index: the index of the current item in the loop; Which starts […]

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

Laravel download files via FTP

This post is going to be about downloading files from the remote server via FTP mechanism in your Laravel application. Let’s create a controller called DownloadController.php Now let’s inform about this controller to routes/web.php That’s it. Now point your browser to http://yourhost.com/downloadFile?file=remote_path/fileName.png.

Categories
Laravel

Create REST API with the Laravel 5.5

This tutorial provides an example of building a complete RESTful API using Laravel 5.5.* Framework. You gonna use the different HTTP methods during the REST API development, quick introduction about each method. GET to retrieve data POST to add data PUT to update data DELETE to delete data Each method as a purpose isn’t it?. […]

Categories
Laravel

Coming up in laravel 5.3

Laravel5.3 is coming with following new features, 1. Rollback one migration 2. Blade Foreach Loops (new $loop variable) 3. Eloquent Collections are cleanly serialized and re-pulled by queued jobs 4. Queue console output changed to show the actual class names 5. Ability to customize simple pagination 6. Customizing additional parameters in FirstOrCreate 7. Query Builder […]