Skip to content
Helper functions I find super-duper handy
Branch: master
Clone or download
Latest commit a936fe6 Jul 7, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Remove guard clause Jul 7, 2019
tests changes Apr 28, 2019
.gitignore Add .idea folder to git ignore Feb 4, 2019
.travis.yml Add missing space Mar 18, 2019 Merge pull request #20 from chapeupreto/patch-1 May 10, 2019
composer.json Add faker() helper function Mar 19, 2019
composer.lock Add faker() helper function Mar 19, 2019
phpunit.xml.dist Strip out all the unescessary boilerplate Feb 1, 2019

A collection of awesome helpful functions for Laravel

Travis CI status image


composer require calebporzio/awesome-helpers



Shortcut for: new Carbon or Carbon::parse()

carbon('One year ago');


Makes an ordinary object chainable.

chain(new SomeClass)

// You can use the "carry" constant to pass the result of one method into the other:
chain(new Str)->singular('cars')->ucfirst(carry)();
// Returns "Car"
// Also, you can grab the result of the chain by trailing
// a "()" on the end of it. (Thanks to Taylor Otwell for these two additions)


Run callback under a different database connection.

$tenantPostIds = connection('tenantdb', function () {
    return Post::pluck('id');


Returns sql query with bindings data.

dump_sql(\DB::table('users')->where('email', "blaBla")->where('id', 1)); 
// returns "select * from `users` where `email` = 'blaBla' and `id` = 1"


Shortcut for: $faker = Faker\Factory::create()

faker()->address; // returns random, fake address
faker('address'); // alternate syntax


A shortcut for auth()->user()



echo money(12); // echoes "$12.00"
echo money(12.75); // echoes "$12.75"
echo money(12.75, false); // echos "$13"
echo money(12.75, true, 'en_GB'); // echos "£12.75"
// Note: unless specified otherwise, money() will detect the current locale.


Shortcut for response('', 204). When you don't have anything to return from an endpoint, but you want to return success.

return ok();


Returns the amount of time (in seconds) the provided callback took to execute. Useful for debugging and profiling.

stopwatch(function () {
}); // returns "2.0"


str_between('--thing--', '--'); // returns "thing"
str_between('[thing]', '[', ']'); // returns "thing"

Str::between('--thing--', '--'); // returns "thing"
Str::between('[thing]', '[', ']'); // returns "thing"


Returns capture groups contained in the provided regex pattern.

str_extract('Jan-01-2019', '/Jan-(.*)-2019/'); // returns "01"

Str::extract('Jan-01-2019', '/Jan-(.*)-2019/'); // returns "01"


Checks the provided string against the provided regex pattern.

str_match('Jan-01-2019', '/Jan-.*-2019/'); // returns true
str_match('foo bar baz', 'bar'); // returns true

Str::match('Jan-1-2019', '/Jan-(.*)-2019/'); // returns true


A simple way to use validate a string using Laravel's built-in validation system.

str_validate('', 'regex:/\.net$/|email|max:10');
// returns: ["Format is invalid.", "May not be greater than 10 characters."]

Str::validate('', 'regex:/\.net$/|email|max:10');
// returns: ["Format is invalid.", "May not be greater than 10 characters."]


str_wrap('thing', '--'); // returns "--thing--"

Str::wrap('thing', '--'); // returns "--thing--"


Kind of like dd(), but will open an artisan tinker terminal session with the variables you passed in, so you can play around.

$somethingYouWantToDebug = new StdClass;

Am I missing an awesome helper function?

Submit a PR or issue with helper functions you use or ideas you have for others!

TTFN, Caleb

You can’t perform that action at this time.