Categories
Laravel

Eloquent – A better way to increment or decrements an int

Laravel has in-built increment() and decrement() functions to increase or decrease a value of the column, by 1 or with the given number. Below are the examples: That’s it – it will actually run update column + 1 under the hood. You can specify a second parameter to this function, the amount of incrementing. The […]

Categories
Laravel Code Snippets

Laravel Drop all tables

This is useful for migrations when you can’t rollback. It can easily be run in artisan mode or you can create a console command.

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

Laravel Eloquent Increments and Decrements value

In this post, I would like to show you the hidden and useful functions of Laravel’s Eloquent ORM to Increment and Decrement value of the fields in the database column. In my recent project, I used increment() and decrement() methods to increase and decrease the numbers respectively. How to use increment() and decrement()

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 force download files in Laravel?

Giving download option to the user is a pretty common requirement in today’s web apps for the variety of reasons. For example, if your application is related to online shopping, you might need an invoice download feature, in this scenario, you might need to force the user’s browser to download the file at the given […]

Categories
Laravel

How to Clear cache in Laravel 5

Here I am gonna show you few artisan commands which will help you to clear different caches in your Laravel application. Clear Application Cache To clear application cache use the php artisan cache:clear command. Generally we don’t get access to SSH on shared hosting plans, where we can do something like below shown, place below […]

Categories
Laravel Code Snippets

How to check current installed version of Laravel ?

You can use laravel’s artisan command to check currently installed version of Laravel Framework Version of Laravel Issue below command from your terminal, make sure to be in application root while issuing command.

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 […]

Categories
Laravel

Laravel – Get the full name of a User using Eloquent accessors

Almost in all projects we face this situation where we have first name and last name in two different fields in the database table and we need to combine the names to show users full in the front end.For each project we implement different solution based on the Framework by fallowing DRY principles. Here today […]