More helper functions in Laravel 5.2

This is a series of posts that showcase new features and aha moments in Laravel 5.2

1. Implicit Route Model Binding

2. Simplified Eloquent Global Scopes

3. Append Scheduled Tasks Output

4. Form Array Validation

5. Middleware Groups

6. Auth Scaffolding

7.  Api Rate Limiting

8. More helper functions

9. Fluent Routing

There are Facades and there are helper functions.

Several Facades have helper function equivalents e.g

Response Facade has response()

Collection Facade has collection()

I am a sucker for helper functions because they are very handy to use.

Here is a list of new helper functions that came bundled with Laravel 5.2:

1. validator()

The validator function creates a new Validator instance.

Remember the Validator Facade? With it, it’s like this:

..but with the validator helper function, we can perform a validation like so:

You can also pass custom messages and attributes to it because this is the signature for the validator function in Laravel source code:

2. resource_path()

The resource_path function returns the path to the resources folder.

3. dispatch()

The dispatch function pushes a new job onto the Laravel job queue.

I can do something like so:

where CleanDB is a Job Class that performs some operations to clean the db after some period.

Note: I’ll keep updating this post as new helper functions are added in Laravel 5.2

Please, if you have any questions or observations, let me know in the comments section below :smile:




Food Ninja, Code Slinger, Technical Trainer, Accidental Writer, Open Source Advocate and Developer Evangelist.