2017 © Pedro Peláez
 

library helpers

A collection of useful helper functions for in Laravel applications.

image

sven/helpers

A collection of useful helper functions for in Laravel applications.

  • Sunday, January 14, 2018
  • by svenluijten
  • Repository
  • 2 Watchers
  • 19 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

helpers, (*1)

Helpers

Latest Version on Packagist Total Downloads ![Software License][ico-license] ![Build Status][ico-circleci] StyleCI, (*2)

This is a collection of useful helpers for use in Laravel applications. Mainly made for personal use, but if you find (some of) the helpers useful, feel free to use it!, (*3)

Installation

Via composer:, (*4)

$ composer require sven/helpers

Or add the package to your dependencies in composer.json and run composer install on the command line to download the package:, (*5)

{
    "require": {
        "sven/helpers": "^1.0"
    }
}

Available functions

All available functions are listed here, along with their usage and an example on how I would use them., (*6)

active_route

This function will return true if you're on the given route name, false otherwise:, (*7)

$isHome = active_route('home');

You may also pass in optional $positive or $negative values to return:, (*8)

$isContact = active_route('contact', 'Yes!', 'No :(');

There is also an option to give it an array of multiple route names instead of just one. The function will return $positive if the current route matches any of the given ones, $negative otherwise:, (*9)

$isContactOrAbout = active_route(['contact', 'about']);

active_route() can be tremendously useful for active states on for instance navigation in blade templates:, (*10)

<nav>
    <ul>
        <li class="{{ active_route('home', 'active', null) }}">
            <a href="{{ route('home') }}">Home</a>
        </li>
        <li class="{{ active_route('contact', 'active', null) }}">
            <a href="{{ route('contact') }}">Contact</a>
        </li>
        <li class="{{ active_route('about', 'active', null) }}">
            <a href="{{ route('about') }}}">About</a>
        </li>
    </ul>
</nav>

str_possessive

This function will return the possessive form of a subject string you give it:, (*11)

echo str_possessive('Brian') . ' house.'; // "Brian's house."

It will only append an apostrophe (without the trailing s) if the given subject ends in s, z or ch:, (*12)

echo str_possessive('Dolores') . ' eyes.'; // "Dolores' eyes."
echo str_possessive('Sanchez') . ' shoes.'; // "Sanchez' shoes."
echo str_possessive('Gretch') . ' plate.'; // "Gretch' plate."

pipe

The pipe() function will simply return an instance of the \Illuminate\Pipeline\Pipeline class from Laravel's container, which allows for some neat chaining:, (*13)

echo pipe('hello')->through([
    AddComma::class,
    AddWorld::class,
])->then(function ($content) {
    return $content;
}); // This will output "hello, world!"

// AddComma class:
class AddComma
{
    public function handle($string, Closure $next)
    {
        return $next($string . ',');
    }
}

// AddWorld class:
class AddWorld
{
    public function handle($string, Closure $next)
    {
        return $next($string . ' world!');
    }
}

Contributing

All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the CONTRIBUTING.md first, though. See the contributors page for all contributors., (*14)

License

sven/helpers is licensed under the MIT License (MIT). Please see the license file for more information., (*15)

The Versions

14/01 2018

dev-master

9999999-dev

A collection of useful helper functions for in Laravel applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

helpers development functions useful

14/01 2018

v1.2.0

1.2.0.0

A collection of useful helper functions for in Laravel applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

helpers development functions useful

14/01 2018

dev-analysis-Xk42nP

dev-analysis-Xk42nP

A collection of useful helper functions for in Laravel applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

helpers development functions useful

09/09 2017

1.1.1

1.1.1.0

A collection of useful helper functions for in Laravel applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

helpers development functions useful

13/05 2017

v1.1.0

1.1.0.0

A collection of useful helper functions for in Laravel applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

helpers development functions useful

12/03 2017

1.0.1

1.0.1.0

A collection of useful helper functions for in Laravel applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

helpers development functions useful

12/03 2017

1.0.0

1.0.0.0

A collection of useful helper functions for in Laravel applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

helpers development functions useful

25/02 2017

1.0.0-beta

1.0.0.0-beta

A collection of useful helper functions for in Laravel applications.

  Sources   Download

MIT

The Requires

 

The Development Requires

helpers development functions useful