Need help with laravel-helpers?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

rappasoft
236 Stars 68 Forks 40 Commits 0 Opened issues

Description

Laravel 5 Helper function for Non-Laravel Projects

Services available

!
?

Need anything else?

Contributors list

# 6,313
PHP
Shell
laravel...
Laravel
15 commits
# 503,356
PHP
3 commits
# 621,286
PHP
1 commit
# 376,443
Ansible
tls-cer...
PHP
Laravel
1 commit
# 206,530
Laravel
PHP
visa
cloud-r...
1 commit
# 4,358
Shell
study-p...
develop...
PHP
1 commit
# 112,045
Laravel
TypeScr...
Less
Shell
1 commit
# 182,621
PHP
errors
C
laravel...
1 commit

Package Logo

Laravel Helpers for Non-Laravel Projects

Latest Version on Packagist Total Downloads

This project takes the useful Laravel helper functions and allows you to use them in Non-Laravel projects.

Installation

composer require rappasoft/laravel-helpers

Documentation

Arrays

array_accessible

/**
 * Determine whether the given value is array accessible.
 *
 * @param  mixed  $value
 *
 * @return bool
 */
function array_accessible($value): bool

array_add

/**
 * Add an element to an array using "dot" notation if it doesn't exist.
 *
 * @param  array  $array
 * @param  string  $key
 * @param  mixed  $value
 *
 * @return array
 */
function array_add(array $array, string $key, $value): array

array_collapse

/**
 * Collapse an array of arrays into a single array.
 *
 * @param  iterable  $array
 *
 * @return array
 */
function array_collapse(iterable $array): array

arraycrossjoin

/**
 * Cross join the given arrays, returning all possible permutations.
 *
 * @param  iterable  ...$arrays
 *
 * @return array
 */
function array_cross_join(...$arrays): array

array_divide

/**
 * Divide an array into two arrays. One with keys and the other with values.
 *
 * @param  array  $array
 *
 * @return array
 */
function array_divide(array $array): array

array_dot

/**
 * Flatten a multi-dimensional associative array with dots.
 *
 * @param  iterable  $array
 * @param  string  $prepend
 *
 * @return array
 */
function array_dot(iterable $array, string $prepend = ''): array

array_except

/**
 * Get all of the given array except for a specified array of keys.
 *
 * @param  array  $array
 * @param  array|string  $keys
 *
 * @return array
 */
function array_except(array $array, $keys): array

array_exists

/**
 * Determine if the given key exists in the provided array.
 *
 * @param  \ArrayAccess|array  $array
 * @param  string|int  $key
 *
 * @return bool
 */
function array_exists($array, $key): bool

array_first

/**
 * Return the first element in an array passing a given truth test.
 *
 * @param  iterable  $array
 * @param  callable|null  $callback
 * @param  mixed  $default
 *
 * @return mixed
 */
function array_first(iterable $array, callable $callback = null, $default = null)

array_last

/**
 * Return the last element in an array passing a given truth test.
 *
 * @param  array  $array
 * @param  callable|null  $callback
 * @param  mixed  $default
 *
 * @return mixed
 */
function array_last(array $array, callable $callback = null, $default = null)

array_flatten

/**
 * Flatten a multi-dimensional array into a single level.
 *
 * @param  iterable  $array
 * @param  int  $depth
 *
 * @return array
 */
function array_flatten(iterable $array, int $depth): array

array_forget

/**
 * Remove one or many array items from a given array using "dot" notation.
 *
 * @param  array  $array
 * @param  array|string  $keys
 *
 * @return void
 */
function array_forget(array &$array, $keys)

array_get

/**
 * Get an item from an array using "dot" notation.
 *
 * @param  \ArrayAccess|array  $array
 * @param  string|int|null  $key
 * @param  mixed  $default
 *
 * @return mixed
 */
function array_get($array, $key, $default = null)

array_has

/**
 * Check if an item or items exist in an array using "dot" notation.
 *
 * @param  \ArrayAccess|array  $array
 * @param  string|array  $keys
 *
 * @return bool
 */
function array_has($array, $keys): bool

arrayhasany

 /**
 * Determine if any of the keys exist in an array using "dot" notation.
 *
 * @param  \ArrayAccess|array  $array
 * @param  string|array  $keys
 *
 * @return bool
 */
function array_has_any($array, $keys): bool

arrayisassoc

/**
 * Determines if an array is associative.
 *
 * An array is "associative" if it doesn't have sequential numerical keys beginning with zero.
 *
 * @param  array  $array
 *
 * @return bool
 */
function array_is_assoc(array $array): bool

array_only

/**
 * Get a subset of the items from the given array.
 *
 * @param  array  $array
 * @param  array|string  $keys
 *
 * @return array
 */
function array_only(array $array, $keys): array

array_pluck

/**
 * Pluck an array of values from an array.
 *
 * @param  iterable  $array
 * @param  string|array|int|null  $value
 * @param  string|array|null  $key
 *
 * @return array
 */
function array_pluck(iterable $array, $value, $key = null): array

array_prepend

/**
 * Push an item onto the beginning of an array.
 *
 * @param  array  $array
 * @param  mixed  $value
 * @param  mixed  $key
 *
 * @return array
 */
function array_prepend(array $array, $value, $key = null): array

array_pull

/**
 * Get a value from the array, and remove it.
 *
 * @param  array  $array
 * @param  string  $key
 * @param  mixed  $default
 *
 * @return mixed
 */
function array_pull(array &$array, string $key, $default = null)

array_query

/**
 * Convert the array into a query string.
 *
 * @param  array  $array
 *
 * @return string
 */
function array_query(array $array): string

array_random

/**
 * Get one or a specified number of random values from an array.
 *
 * @param  array  $array
 * @param  int|null  $number
 * @param  bool|false  $preserveKeys
 *
 * @return mixed
 *
 * @throws \InvalidArgumentException
 */
function array_random(array $array, int $number = null, bool $preserveKeys)

array_set

/**
 * Set an array item to a given value using "dot" notation.
 *
 * If no key is given to the method, the entire array will be replaced.
 *
 * @param  array  $array
 * @param  string|null  $key
 * @param  mixed  $value
 *
 * @return array
 */
function array_set(array &$array, ?string $key, $value): array

array_shuffle

 /**
 * Shuffle the given array and return the result.
 *
 * @param  array  $array
 * @param  int|null  $seed
 *
 * @return array
 */
function array_shuffle(array $array, int $seed = null): array

arraysortrecursive

/**
 * Recursively sort an array by keys and values.
 *
 * @param  array  $array
 * @param  int  $options
 * @param  bool  $descending
 *
 * @return array
 */
function array_sort_recursive(array $array, int $options = SORT_REGULAR, bool $descending): array

arraytocss_classes

/**
 * Conditionally compile classes from an array into a CSS class list.
 *
 * @param  array  $array
 *
 * @return string
 */
function array_to_css_classes(array $array): string

array_where

/**
 * Filter the array using the given callback.
 *
 * @param  array  $array
 * @param  callable  $callback
 *
 * @return array
 */
function array_where(array $array, callable $callback): array

array_wrap

/**
 * If the given value is not an array and not null, wrap it in one.
 *
 * @param  mixed  $value
 *
 * @return array
 */
function array_wrap($value): array

data_fill

/**
 * Fill in data where it's missing.
 *
 * @param  mixed  $target
 * @param  string|array  $key
 * @param  mixed  $value
 * @return mixed
 */
function data_fill(&$target, $key, $value)

data_get

/**
 * Get an item from an array or object using "dot" notation.
 *
 * @param  mixed  $target
 * @param  string|array|int|null  $key
 * @param  mixed  $default
 * @return mixed
 */
function data_get($target, $key, $default = null)

data_set

/**
 * Set an item on an array or object using dot notation.
 *
 * @param  mixed  $target
 * @param  string|array  $key
 * @param  mixed  $value
 * @param  bool  $overwrite
 *
 * @return mixed
 */
function data_set(&$target, $key, $value, bool $overwrite = true)

head

/**
 * Get the first element of an array. Useful for method chaining.
 *
 * @param  array  $array
 *
 * @return mixed
 */
function head(array $array)

last

/**
 * Get the last element from an array.
 *
 * @param  array  $array
 *
 * @return mixed
 */
function last(array $array)

Strings

pregreplacearray

/**
 * Replace a given pattern with each value in the array in sequentially.
 *
 * @param  string  $pattern
 * @param  array  $replacements
 * @param  string  $subject
 *
 * @return string
 */
function preg_replace_array(string $pattern, array $replacements, string $subject): string

str_after

/**
 * Return the remainder of a string after the first occurrence of a given value.
 *
 * @param  string  $subject
 * @param  string  $search
 *
 * @return string
 */
function str_after(string $subject, string $search): string

strafterlast

/**
 * Return the remainder of a string after the last occurrence of a given value.
 *
 * @param  string  $subject
 * @param  string  $search
 *
 * @return string
 */
function str_after_last(string $subject, string $search): string

str_before

/**
 * Get the portion of a string before the first occurrence of a given value.
 *
 * @param  string  $subject
 * @param  string  $search
 *
 * @return string
 */
function str_before(string $subject, string $search): string

strbeforelast

/**
 * Get the portion of a string before the last occurrence of a given value.
 *
 * @param  string  $subject
 * @param  string  $search
 *
 * @return string
 */
function str_before_last(string $subject, string $search): string

str_between

/**
 * Get the portion of a string between two given values.
 *
 * @param  string  $subject
 * @param  string  $from
 * @param  string  $to
 *
 * @return string
 */
function str_between(string $subject, string $from, string $to): string

str_contains

 /**
 * Determine if a given string contains a given substring.
 *
 * @param  string  $haystack
 * @param  string|string[]  $needles
 *
 * @return bool
 */
function str_contains(string $haystack, $needles): bool

strcontainsall

/**
 * Determine if a given string contains all array values.
 *
 * @param  string  $haystack
 * @param  string[]  $needles
 *
 * @return bool
 */
function str_contains_all(string $haystack, array $needles): bool

strendswith

/**
 * Determine if a given string ends with a given substring.
 *
 * @param  string  $haystack
 * @param  string|string[]  $needles
 *
 * @return bool
 */
function str_ends_with(string $haystack, $needles): bool

str_finish

/**
 * Cap a string with a single instance of a given value.
 *
 * @param  string  $value
 * @param  string  $cap
 *
 * @return string
 */
function str_finish(string $value, string $cap): string

str_is

/**
 * Determine if a given string matches a given pattern.
 *
 * @param  string|array  $pattern
 * @param  string  $value
 *
 * @return bool
 */
function str_is($pattern, string $value): bool

strisuuid

/**
 * Determine if a given string is a valid UUID.
 *
 * @param  string  $value
 *
 * @return bool
 */
function str_is_uuid(string $value): bool

str_kebab

/**
 * Convert a string to kebab case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_kebab(string $value): string

str_length

/**
 * Return the length of the given string.
 *
 * @param  string  $value
 * @param  string|null  $encoding
 *
 * @return int
 */
function str_length(string $value, string $encoding = null): int

str_limit

/**
 * Limit the number of characters in a string.
 *
 * @param  string  $value
 * @param  int  $limit
 * @param  string  $end
 *
 * @return string
 */
function str_limit(string $value, int $limit = 100, string $end = '...'): string

str_lower

/**
 * Convert the given string to lower-case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_lower(string $value): string

str_words

/**
 * Limit the number of words in a string.
 *
 * @param  string  $value
 * @param  int  $words
 * @param  string  $end
 *
 * @return string
 */
function str_words(string $value, int $words = 100, string $end = '...'): string

str_match

/**
 * Get the string matching the given pattern.
 *
 * @param  string  $pattern
 * @param  string  $subject
 *
 * @return string
 */
function str_match(string $pattern, string $subject): string

strpadboth

/**
 * Pad both sides of a string with another.
 *
 * @param  string  $value
 * @param  int  $length
 * @param  string  $pad
 *
 * @return string
 */
function str_pad_both(string $value, int $length, string $pad = ' '): string

strpadleft

/**
 * Pad the left side of a string with another.
 *
 * @param  string  $value
 * @param  int  $length
 * @param  string  $pad
 *
 * @return string
 */
function str_pad_left(string $value, int $length, string $pad = ' '): string

strpadright

/**
 * Pad the right side of a string with another.
 *
 * @param  string  $value
 * @param  int  $length
 * @param  string  $pad
 *
 * @return string
 */
function str_pad_right(string $value, int $length, string $pad = ' '): string

str_random

/**
 * Generate a more truly "random" alpha-numeric string.
 *
 * @param  int  $length
 *
 * @return string
 */
function str_random(int $length = 16): string

strreplacearray

/**
 * Replace a given value in the string sequentially with an array.
 *
 * @param  string  $search
 * @param  array  $replace
 * @param  string  $subject
 *
 * @return string
 */
function str_replace_array(string $search, array $replace, string $subject): string

strreplacefirst

/**
 * Replace the first occurrence of a given value in the string.
 *
 * @param  string  $search
 * @param  string  $replace
 * @param  string  $subject
 *
 * @return string
 */
function str_replace_first(string $search, string $replace, string $subject): string

strreplacelast

/**
 * Replace the last occurrence of a given value in the string.
 *
 * @param  string  $search
 * @param  string  $replace
 * @param  string  $subject
 *
 * @return string
 */
function str_replace_last(string $search, string $replace, string $subject): string

str_remove

/**
 * Remove any occurrence of the given string in the subject.
 *
 * @param  string|array  $search
 * @param  string  $subject
 * @param  bool  $caseSensitive
 *
 * @return string
 */
function str_remove($search, string $subject, bool $caseSensitive = true): string

str_start

/**
 * Begin a string with a single instance of a given value.
 *
 * @param  string  $value
 * @param  string  $prefix
 *
 * @return string
 */
function str_start(string $value, string $prefix): string

str_upper

/**
 * Convert the given string to upper-case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_upper(string $value): string

str_title

/**
 * Convert the given string to title case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_title(string $value): string

str_snake

/**
 * Convert a string to snake case.
 *
 * @param  string  $value
 * @param  string  $delimiter
 *
 * @return string
 */
function str_snake(string $value, string $delimiter = '_'): string

strstartswith

/**
 * Determine if a given string starts with a given substring.
 *
 * @param  string  $haystack
 * @param  string|string[]  $needles
 *
 * @return bool
 */
function str_starts_with(string $haystack, $needles): bool

str_studly

 /**
 * Convert a value to studly caps case.
 *
 * @param  string  $value
 *
 * @return string
 */
function str_studly(string $value): string

Classes

class_basename

/**
 * Get the class "basename" of the given object / class.
 *
 * @param  string|object  $class
 * @return string
 */
function class_basename($class): string

classusesrecursive

/**
 * Returns all traits used by a class, its parent classes and trait of their traits.
 *
 * @param  object|string  $class
 * @return array
 */
function class_uses_recursive($class): array

traitusesrecursive

/**
 * Returns all traits used by a trait and its traits.
 *
 * @param  string  $trait
 * @return array
 */
function trait_uses_recursive($trait): array

Miscellaneous

dd

/**
 * Dump the passed variables and end the script.
 *
 * @param  mixed
 * @return void
 */
function dd()

e

/**
 * Escape HTML entities in a string.
 *
 * @param  string  $value
 *
 * @return string
 */
function e(string $value): string

object_get

 /**
 * Get an item from an object using "dot" notation.
 *
 * @param  object  $object
 * @param  string  $key
 * @param  mixed $default
 *
 * @return mixed
 */
function object_get(object $object, string $key, $default = null)

tap

/**
 * Call the given Closure with the given value then return the value.
 *
 * @param  mixed $value
 * @param  callable  $callback
 *
 * @return mixed
 */
function tap($value, callable $callback)

value

/**
 * Return the default value of the given value.
 *
 * @param  mixed $value
 * @return mixed
 */
function value($value)

with

/**
 * Return the given object. Useful for chaining.
 *
 * @param  mixed $object
 * @return mixed
 */
function with($object)

License

Since the Laravel framework is open-sourced software licensed under the MIT license, this project is licensed under the same license.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.