Categories
Laravel

How to Upload, download, remove Files to Amazon S3 Using Laravel

Create a controller called UploadController.php with following code. Create a view file Create a file called upload.blade.php in the resources/views directory and place below inside it. Define Routes Open your routes/web.php directory and add following route definitions to it.

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

Multiple Route files in Laravel 5

For small-scale applications single route file is sufficient but large-scale applications its cumbersome to maintain and organize the routes. The solution for this was creating multiple route files. For example, if you are developing web application and APIs in the same application than its elegant to create separate route files for each. Even you can […]

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

How to add custom class in Laravel 5

In this tutorial, I will show you how to add a custom PHP class in Laravel 5.x application. For example, Lets call our class Common.php. Create a directory called Mylibs in app directory along with your class, Ex: Common.php. Make sure to add the correct namespace to the class as for your directory structure, in […]

Categories
Laravel

Laravel 5 get current authenticated user?

Upon successful login you can get current user details by called Auth::user() method. It will return null if no user logged in or there is no current user. On successful login Auth::user() return value is based on your authentication configuration. If your driver is eloquent then the object return is the class specified by the […]

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

Laravel 5 render a view and store it’s contents in a variable

Sometimes you may want send the rendered view in the ajax response instead of showing on the browser. To return html in the ajax response first you need to store the blade engine compiled HTML into the variable in side your controller action then you need to return the variable, you can store the compiled […]

Categories
Laravel

Laravel 5 Eloquent – Attribute casting

One of the Laravel 5 awesome feature is Attribute casting. Casting attribute means changing the attribute values to a particular type. for example Boolean, integer, strings. Eloquent models allows you to change datatype of the Attribute values automatically with Attribute casting feature.To cast a attribute of the model ,all you have to do is just […]

Categories
Laravel

Where NOT in Eloquent join Relation

Here is the simple laravel’s eloquent code snippet to get results in a table when there are no results for the relationship. I have two tables called users and accounts. each account belong to one user ,some users not belong to any account they are just users, they can only view the stuff which is […]