2017 © Pedro Peláez
 

library helper-functions

Laravel-specific and pure PHP helper functions.

image

illuminated/helper-functions

Laravel-specific and pure PHP helper functions.

  • Monday, July 23, 2018
  • by dmitry-ivanov
  • Repository
  • 3 Watchers
  • 61 Stars
  • 10,303 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 96 Versions
  • 24 % Grown

The README.md

Laravel-specific and pure PHP Helper Functions, (*1)

Laravel Helper Functions

Buy me a coffee, (*2)

StyleCI Build Status Coverage Status, (*3)

Packagist Version Packagist Stars Packagist Downloads Packagist License, (*4)

Laravel-specific and pure PHP Helper Functions., (*5)

Laravel Helper Functions
11.x Support
10.x 10.x
9.x 9.x
8.x 8.x
7.x 7.x
6.x 6.x
5.8.* 5.8.*
5.7.* 5.7.*
5.6.* 5.6.*
5.5.* 5.5.*
5.4.* 5.4.*
5.3.* 5.3.*
5.2.* 5.2.*
5.1.* 5.1.*

Usage

  1. Install the package via Composer:, (*6)

    shell script composer require illuminated/helper-functions, (*7)

  2. Use any of the provided helper functions:, (*8)

    if (is_windows_os()) {
        call_in_background('switch-to-mac');
    }
    

Available functions

Feel free to contribute., (*9)

Array

array_except_value()

Remove the given values from the array:, (*21)

array_except_value(['foo', 'bar', 'baz'], 'baz');

// ["foo", "bar"]
array_except_value(['foo', 'bar', 'baz'], ['bar', 'baz']);

// ["foo"]

multiarray_set()

Set the value for each item of the multidimensional array using "dot" notation:, (*22)

$array = [
    ['name' => 'Mercedes-Benz', 'details' => ['type' => 'SUV']],
    ['name' => 'BMW', 'details' => ['type' => 'SUV']],
    ['name' => 'Porsche', 'details' => ['type' => 'SUV']],
];

multiarray_set($array, 'details.country', 'Germany');

// [
//     ["name" => "Mercedes-Benz", "details" => ["type" => "SUV", "country" => "Germany"]],
//     ["name" => "BMW", "details" => ["type" => "SUV", "country" => "Germany"]],
//     ["name" => "Porsche", "details" => ["type" => "SUV", "country" => "Germany"]],
// ]

multiarray_sort_by()

Sort the multidimensional array by several fields:, (*23)

$array = [
    ['name' => 'Mercedes-Benz', 'model' => 'GLS', 'price' => 120000],
    ['name' => 'Mercedes-Benz', 'model' => 'GLE Coupe', 'price' => 110000],
    ['name' => 'BMW', 'model' => 'X6', 'price' => 77000],
    ['name' => 'Porsche', 'model' => 'Cayenne', 'price' => 117000],
];

$sorted = multiarray_sort_by($array, 'name', 'model');

// [
//     ["name" => "BMW", "model" => "X6", "price" => 77000],
//     ["name" => "Mercedes-Benz", "model" => "GLE Coupe", "price" => 110000],
//     ["name" => "Mercedes-Benz", "model" => "GLS", "price" => 120000],
//     ["name" => "Porsche", "model" => "Cayenne", "price" => 117000],
// ]

Also, you can change the sort order:, (*24)

$array = [
    ['name' => 'Mercedes-Benz', 'model' => 'GLS', 'price' => 120000],
    ['name' => 'Mercedes-Benz', 'model' => 'GLE Coupe', 'price' => 110000],
    ['name' => 'BMW', 'model' => 'X6', 'price' => 77000],
    ['name' => 'Porsche', 'model' => 'Cayenne', 'price' => 117000],
];

$sorted = multiarray_sort_by($array, 'name', SORT_ASC, 'model', SORT_DESC);

// [
//     ["name" => "BMW", "model" => "X6", "price" => 77000],
//     ["name" => "Mercedes-Benz", "model" => "GLS", "price" => 120000],
//     ["name" => "Mercedes-Benz", "model" => "GLE Coupe", "price" => 110000],
//     ["name" => "Porsche", "model" => "Cayenne", "price" => 117000],
// ]

Artisan

call_in_background()

Call the given artisan console command in background., (*25)

Code execution continues immediately, without waiting for results., (*26)

call_in_background('report');

// "php artisan report" would be called in background

Optional before and after sub-commands could be used:, (*27)

call_in_background('report:monthly subscriptions', 'sleep 0.3');

// "sleep 0.3 && php artisan report:monthly subscriptions" would be called in background

Database

db_is_sqlite()

Check whether the default database connection driver is sqlite or not:, (*28)

db_is_sqlite();

// false

db_is_mysql()

Check whether the default database connection driver is mysql or not:, (*29)

db_is_mysql();

// true

db_mysql_now()

Get the current MySQL datetime:, (*30)

db_mysql_now();

// "2020-05-25 20:09:33"

db_mysql_variable()

Get value of the specified MySQL variable:, (*31)

db_mysql_variable('hostname');

// "localhost"

Date

to_default_timezone()

Convert the given datetime to the default timezone (see app.timezone config):, (*32)

to_default_timezone('2017-02-28T14:05:01Z');

// "2017-02-28 16:05:01", assuming that `app.timezone` is "Europe/Kiev"

Debug

backtrace_as_string()

Get backtrace without arguments, as a string:, (*33)

$backtrace = backtrace_as_string();

#0  backtrace_as_string() called at [/htdocs/example/routes/web.php:15]
#1  Illuminate\Routing\Router->{closure}() called at [/htdocs/example/vendor/laravel/framework/src/Illuminate/Routing/Route.php:189]
#2  Illuminate\Foundation\Http\Kernel->handle() called at [/htdocs/example/public/index.php:53]

minimized_backtrace_as_string()

Get minimized backtrace, as a string:, (*34)

$backtrace = minimized_backtrace_as_string();

#0 /htdocs/example/routes/web.php:15
#1 /htdocs/example/vendor/laravel/framework/src/Illuminate/Routing/Route.php:189
#2 /htdocs/example/public/index.php:53

Email

is_email()

Check whether the given string is an email address or not:, (*35)

is_email('john.doe@example.com');

// true

to_rfc2822_email()

Convert addresses data to RFC 2822 string, suitable for PHP mail() function:, (*36)

to_rfc2822_email([
    ['address' => 'john.doe@example.com', 'name' => 'John Doe'],
    ['address' => 'jane.smith@example.com'],
]);

// "John Doe <john.doe@example.com>, jane.smith@example.com"

Also, it supports simplified syntax for a single address:, (*37)

to_rfc2822_email(['address' => 'john.doe@example.com', 'name' => 'John Doe']);

// "John Doe <john.doe@example.com>"

to_swiftmailer_emails()

Convert addresses data to SwiftMailer-suitable format:, (*38)

to_swiftmailer_emails([
    ['address' => 'john.doe@example.com', 'name' => 'John Doe'],
    ['address' => 'jane.smith@example.com'],
]);

// ["john.doe@example.com" => "John Doe", "jane.smith@example.com"]

Also, it supports simplified syntax for a single address:, (*39)

to_swiftmailer_emails(['address' => 'john.doe@example.com', 'name' => 'John Doe']);

// ["john.doe@example.com" => "John Doe"]

to_symfony_emails()

Convert addresses data to Symfony-suitable format:, (*40)

to_symfony_emails([
    ['address' => 'john.doe@example.com', 'name' => 'John Doe'],
    ['address' => 'jane.smith@example.com'],
]);

// ["John Doe <john.doe@example.com>", "jane.smith@example.com"]

Also, it supports simplified syntax for a single address:, (*41)

to_symfony_emails(['address' => 'john.doe@example.com', 'name' => 'John Doe']);

// ["John Doe <john.doe@example.com>"]

Filesystem

relative_path()

Get a relative path for the given folders:, (*42)

relative_path('/var/www/htdocs', '/var/www/htdocs/example');

// "../"

You can pass the relative path as a parameter too:, (*43)

relative_path('/var/www/htdocs/example/public/../../', '/var/');

// "www/htdocs/"

Format

get_dump()

Get a nicely formatted string representation of the variable, using the Symfony VarDumper Component:, (*44)

$array = [
    'a simple string' => 'Hello!',
    'a float' => 1.0,
    'an integer' => 1,
    'a boolean' => true,
    'an empty array' => [],
];

$dump = get_dump($array);

// array:5 [
//     "a simple string" => "Hello!"
//     "a float" => 1.0
//     "an integer" => 1
//     "a boolean" => true
//     "an empty array" => []
// ]

format_bytes()

Format bytes into kilobytes, megabytes, gigabytes or terabytes:, (*45)

format_bytes(3333333);

// "3.18 MB"

format_xml()

Format the given XML string using new lines and indents:, (*46)

format_xml('<root><task priority="low"><to>John</to><from>Jane</from><title>Go to the shop</title></task><task priority="medium"><to>John</to><from>Paul</from><title>Finish the report</title></task><task priority="high"><to>Jane</to><from>Jeff</from><title>Clean the house</title></task></root>');

// 
// <root>
//   <task priority="low">
//     <to>John</to>
//     <from>Jane</from>
//     <title>Go to the shop</title>
//   </task>
//   <task priority="medium">
//     <to>John</to>
//     <from>Paul</from>
//     <title>Finish the report</title>
//   </task>
//   <task priority="high">
//     <to>Jane</to>
//     <from>Jeff</from>
//     <title>Clean the house</title>
//   </task>
// </root>

Json

is_json()

Check whether the given value is a valid JSON-encoded string or not:, (*47)

is_json('{"foo":1,"bar":2,"baz":3}');

// true

It returns decoded JSON if you pass true as a second argument:, (*48)

is_json('{"foo":1,"bar":2,"baz":3}', true);

// ["foo" => 1, "bar" => 2, "baz" => 3]

System

is_windows_os()

Check whether the operating system is Windows or not:, (*49)

is_windows_os();

// false

Xml

xml_to_array()

Convert the given XML to array:, (*50)

xml_to_array('
<Guys>
    <Good_guy Rating="100">
        <name>Luke Skywalker</name>
        <weapon>Lightsaber</weapon>
    </Good_guy>
    <Bad_guy Rating="90">
        <name>Sauron</name>
        <weapon>Evil Eye</weapon>
    </Bad_guy>
</Guys>
');

// [
//     "Good_guy" => [
//         "name" => "Luke Skywalker",
//         "weapon" => "Lightsaber",
//         "@attributes" => [
//             "Rating" => "100",
//         ],
//     ],
//     "Bad_guy" => [
//         "name" => "Sauron",
//         "weapon" => "Evil Eye",
//         "@attributes" => [
//             "Rating" => "90",
//         ],
//     ],
// ]

Alternatively, you can pass an instance of the SimpleXMLElement class instead of a string., (*51)

array_to_xml()

Convert the given array to XML string:, (*52)

$array = [
    'Good guy' => [
        'name' => 'Luke Skywalker',
        'weapon' => 'Lightsaber',
        '@attributes' => [
            'Rating' => '100',
        ],
    ],
    'Bad guy' => [
        'name' => 'Sauron',
        'weapon' => 'Evil Eye',
        '@attributes' => [
            'Rating' => '90',
        ],
    ]
];

$xml = array_to_xml($array, 'Guys');

// 
// <Guys>
//    <Good_guy Rating="100">
//        <name>Luke Skywalker</name>
//        <weapon>Lightsaber</weapon>
//    </Good_guy>
//    <Bad_guy Rating="90">
//        <name>Sauron</name>
//        <weapon>Evil Eye</weapon>
//    </Bad_guy>
// </Guys>

Sponsors

Laravel Idea
Material Theme UI Plugin
, (*53)

License

Laravel Helper Functions is open-sourced software licensed under the MIT license., (*54)

Buy me a coffee , (*55)

The Versions

23/07 2018

5.6.x-dev

5.6.9999999.9999999-dev

Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

23/07 2018

5.5.x-dev

5.5.9999999.9999999-dev

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

23/07 2018

5.4.x-dev

5.4.9999999.9999999-dev

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

23/07 2018
23/07 2018
23/07 2018
23/02 2018
18/02 2018
18/02 2018

5.6.0

5.6.0.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

24/01 2018
19/01 2018
12/01 2018
07/09 2017
07/09 2017
07/09 2017
07/09 2017
06/09 2017
06/09 2017
06/09 2017
06/09 2017
06/09 2017
06/09 2017
06/09 2017
07/03 2017
02/03 2017
28/02 2017
20/02 2017

1.0.18

1.0.18.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

20/02 2017

1.0.17

1.0.17.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

18/02 2017

1.0.16

1.0.16.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

17/02 2017

1.0.15

1.0.15.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

17/02 2017

1.0.14

1.0.14.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

16/02 2017

1.0.13

1.0.13.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

15/02 2017

1.0.12

1.0.12.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

29/01 2017

1.0.11

1.0.11.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

28/12 2016

1.0.10

1.0.10.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

24/12 2016

1.0.9

1.0.9.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

09/12 2016

1.0.8

1.0.8.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

24/11 2016

1.0.7

1.0.7.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

01/11 2016

1.0.6

1.0.6.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

27/10 2016

1.0.5

1.0.5.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

14/10 2016

1.0.4

1.0.4.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

27/09 2016

1.0.3

1.0.3.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

23/09 2016

1.0.2

1.0.2.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

18/09 2016

1.0.1

1.0.1.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

17/09 2016

1.0.0

1.0.0.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

17/09 2016

0.1.32

0.1.32.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

17/09 2016

0.1.31

0.1.31.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

15/09 2016

0.1.30

0.1.30.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

15/09 2016

0.1.29

0.1.29.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

15/09 2016

0.1.28

0.1.28.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

15/09 2016

0.1.27

0.1.27.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

15/09 2016

0.1.26

0.1.26.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

14/09 2016

0.1.25

0.1.25.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

14/09 2016

0.1.24

0.1.24.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

14/09 2016

0.1.23

0.1.23.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Dmitry Ivanov

laravel function helper

13/09 2016

0.1.22

0.1.22.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

26/07 2016

0.1.21

0.1.21.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

19/07 2016

0.1.20

0.1.20.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

15/07 2016

0.1.19

0.1.19.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

07/07 2016

0.1.18

0.1.18.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

07/07 2016

0.1.17

0.1.17.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

02/07 2016

0.1.16

0.1.16.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

02/07 2016

0.1.15

0.1.15.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

02/07 2016

0.1.14

0.1.14.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

01/07 2016

0.1.13

0.1.13.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

29/06 2016

0.1.12

0.1.12.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

29/06 2016

0.1.11

0.1.11.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

25/06 2016

0.1.10

0.1.10.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

25/06 2016

0.1.9

0.1.9.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

23/06 2016

0.1.8

0.1.8.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

18/06 2016

0.1.7

0.1.7.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

18/06 2016

0.1.6

0.1.6.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

18/06 2016

0.1.5

0.1.5.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

 

by Dmitry Ivanov

laravel function helper

17/06 2016

0.1.4

0.1.4.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Dmitry Ivanov

laravel function helper

17/06 2016

0.1.3

0.1.3.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Dmitry Ivanov

laravel function helper

17/06 2016

0.1.2

0.1.2.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Dmitry Ivanov

laravel function helper

17/06 2016

0.1.1

0.1.1.0

Provides Laravel-specific and pure PHP helper functions.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Dmitry Ivanov

laravel function helper