Download the PHP package darkghosthunter/larahelp without Composer
On this page you can find all versions of the php package darkghosthunter/larahelp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download darkghosthunter/larahelp
More information about darkghosthunter/larahelp
Files in darkghosthunter/larahelp
Package larahelp
Short Description Supercharge your Laravel projects with useful global helpers.
License MIT
Homepage https://github.com/darkghosthunter/larahelp
Informations about the package larahelp
Larahelp
Supercharge your Laravel projects with more than 25 useful global helpers.
Requisites
- Laravel 8.x or later
- PHP 8.0 or later
Installation
You can install the package via composer:
This package is focused on the backend. If you want views helpers, I recommend you to use custom Blade directives instead.
Usage
This package includes helpful global helpers for your project make almost anything into beautiful one liners:
app_call | in_development | route_is |
call_existing | logged_in | shadow |
created | methods_of | sleep_between |
data_update | missing_trait | taptap |
delist | none_of | undot_path |
diff | object_assign | until |
dot_path | ok | user |
enclose | period | weekend |
files | period_from | weekstart |
has_trait | pipe | which_of |
hashy | remember | yesterday |
in_console | route_is |
app_call()
Executes a callable using the application Container.
call_existing()
Calls a dynamic method or macro if it exists in the object instance. It supports macros and static methods.
created()
Return an HTTP 201 response (OK, Created), with optional content.
data_update()
Updates an item of an array or object using a callback that receives it.
The value will be updated regardless if the key doesn't exists.
delist()
Returns the values of the array, so these can be listed into variables. It accepts an optional offset to remove a given number of first keys.
diff()
Returns the difference between two dates in seconds or any other given unit.
dot_path()
Transforms a relative path into dot notation.
This does not validate file paths. You should append the filename to the dot-path manually.
enclose()
Wraps a value or callable into a Closure, if it's not already callable.
files()
Returns the local Filesystem helper, or a list of files in a path.
has_trait()
Checks recursively if the object is using a single trait.
hashy()
Creates a small BASE64 encoded MD5 hash from a string for portable checksum.
This is very useful to hash large walls of texts, or even files, while compressing the 128-bit hash into a 24-character string.
You can use the same function to compare the hashable string with a hash to note if it was modified.
in_console()
Check if the application is running in console, like when using Artisan or PHPUnit.
It also accepts a callable that will be executed if the condition is true.
in_development()
Check if the application is running in development environments: dev
, development
or local
It also accepts a callable that will be executed if the condition is true.
logged_in()
Executes a single callback while the user is logged in.
It basically logs in and logs out an user while executing the callback, which can be useful to do on guest routes.
It will throw an exception if there is already a user logged in.
methods_of()
Returns a collection of all public methods from a given class or object.
missing_trait()
Checks recursively if the object is not using a trait.
none_of()
Checks if none of the options compared to a subject, or called with it, returns something truthy.
Using a callable, it will receive the subject and the key being compared.
object_assign()
Assigns an array of values to an object, recursively, using dot notation.
ok()
Returns an HTTP 204 response (OK, No Content).
period()
Returns the period of a given start and end or interval. Periods are extremely useful to get multiple dates based on a start, end, a given time between each occurrence.
The most common way to create a period is defining the start, the number of occurrences, and the interval amount.
Alternatively, you can specify a start, and end, and the interval of time until that end.
Once you do, you can iterate each moment of time with a foreach
loop.
period_from()
Returns the next or previous period from given date, exclusive by default.
This is very handy to know when the next or previous moment from a given datetime, like the current time.
The function can also check the previous date by setting $after
to false
.
Dates compared are exclusive. In include the date as inclusive, set
$inclusive
totrue
.
pipe()
Sends an object through a pipeline.
remember()
Retrieves an item from the cache, or stores a default value if the item doesn't exist.
If no ttl
is set, and rather a callback is issued as second parameter, it will be stored forever.
It supports atomic locks, which are created using the same name key. It will lock the key by a given seconds, while also waiting for the same amount of time.
This can be useful to avoid cache data-races, where multiple processes run the same callback because the cache key is not filled yet.
route_is()
Determine whether the current route's name matches the given patterns.
shadow()
Calls a method on an object if it exists, or returns false. It supports Macros.
sleep_between()
Runs a callback while sleeping between multiple executions, returning a Collection of all results.
taptap()
Call the given Closure with the given value then return the value, twice.
undot_path()
Transforms a path from dot notation to a relative path.
until()
Returns the interval from a date until the desired date.
user()
Returns the currently authenticated user, if any.
weekend()
Returns the end of the week. It supports setting what day the week end.
weekstart()
Returns the end of the week. It supports setting what day the week starts.
which_of()
Returns the key of the option which comparison or callback returns true.
If the callback returns something truthy, that value will be used.
yesterday()
Returns the date for yesterday.
Missing a helper?
If you have an idea for a helper, shoot it as an issue. PR with test and good code quality receive priority.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.