Home Laravel 7 laravel helper functions to make your life easier

7 laravel helper functions to make your life easier

laravel helper functions

Laravel provides a lot of global helper functions which are also used by the framework itself. These helpers functions can be used by us to make our work convenient. Laravel helper function also helps us to maintain code reusability by storing the most repetitive task on single global function.

There are many helpers functions for working with arrays and objects, URLs, paths, string and so on. In this article, we are going to include only 10 helper functions.

You can also create your own helper functions in laravel 5. You can find a nice article explaining the steps about creating custom helpers in this article.

Back

1. abort_if()

This new helper function was added in Laravel 5.2. Its was introduced to make the abort function prettier reducting the lines on conditional statement.

The syntax of basic usage:

abort_if( ! $user, 404);

The function accepts parameters as boolean, status code and message.

function abort_if($boolean, $code, $message = '', array $headers = [])
{
        ....
}
Back

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here