This package includes some of the helper functions that I tend to use in all of my projects.
You can install the package via composer:
composer require ryangjchandler/laravel-helpers
Returns the current user, or null depending on authentication status.
This function assumes that your
User
model is found inside ofapp/Models
and will not be registered if that class doesn't exist.
$user = user();
Check if the current route name matches the provided string.
route_is('dashboard.index');
Identical to Laravel's $this->authorize()
method provided by the AuthorizesRequests
trait.
public function index()
{
authorize('viewAny', Post::class);
}
Laravel 9 introduces new directives for checked, disabled and selected. In some cases though, you might want to output a variety of different attributes using PHP values.
attributes()
and the @attributes()
directive can help with that:
<button @attributes([
'disabled' => ! $user->can('click'),
])>
</button>
It's quite common to output an —
in your HTML code when it isn't present. Doing this with regular Blade {{ }}
tags can be annoying though since —
needs to be output in "raw" mode.
This function uses HtmlString
to return a "safe" wrapper around the HTML entity which allows it to be output without being escaped.
{{ $post->published_at?->format('d/m/Y') ?? mdash() }}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.