Laravel Tricks

Browse latest tricks and tips on Laravel.

How to get all records in Laravel?

You can simply use YourModel::all(); to select all records from table with Laravel Eloquent.Example Usage$posts= Post::all(); $posts->each(function($post){   //do ...
published on : 1 day ago 12 Comments

sqlstate hy000 error 2002 laravel

How to resolve sqlstate hy000 error 2002 in laravel.This type of error is occurred due to wrong database configration in .env file. Steps to resolve sqlstate hy000 error in Larave ...
published on : 2 days ago 12 Comments

Laravel delete migration

How to delete a migration file in Laravel?Sometime we accidentally create a migration in laravel later we identify the particular migration is not required. In this post I am going ...
published on : 12 hours ago 12 Comments

PHP artisan optimize command

php artisan optimize is used to remove the boostrap/cache/ directory files and recreates it.From Laravel 5.5 php artisan optimize commnad is removed and no longer needed. ...
published on : 3 hours ago 12 Comments

clear-compiled Command in Laravel

Laravel's clear-compiled is an artisan command to clear the compiled classes and services.To clear compiled classes in Laravel please run below command. php artisan clear-comp ...
published on : 10 hours ago 12 Comments

What is an Initialization function in PHP?

Initialization function is also known as constructor in PHP. The constructor is also a normal function, but it has a special feature that is always called when we initialize an obj ...
published on : 4 hours ago 12 Comments

What happens when AUTO_INCREMENT reaches the maximum value?

When AUTO_INCREMENT reaches the maximum value in MysqlIf the AUTO_INCREMENT column allows only unique values ??such as a primary key? An error occurs due to duplication (unique con ...
published on : 7 hours ago 12 Comments

Disabling error handler in laravel

How to disable error handler in Laravel framework?You can disable error and warning handler in Laravel by simply setting 'debug' => false in your config/app.php ...
published on : 18 hours ago 12 Comments

Adding Multiple Order By clause in Laravel

How to use order By clause in Laravel?Order by is used to sort sql results by column names. In this example we will see how to add multiple orderby clause in Laravel.Let take an ex ...
published on : 10 hours ago 12 Comments

Read and Write Cookie in Laravel 5

Setting and getting cookie in LaravelHi Guys, in this post we are going to see how to read and write cookies in Laravel 5.8. In Laravel all cookies are encrypted and signed with an ...
published on : 9 hours ago 12 Comments