jorisnoo / laravel-helpers

A collection of helper functions that I use across my projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A collection of helper functions that I use across my projects.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package includes some of the helper functions that I tend to use in all of my projects.

Installation

You can install the package via composer:

composer require ryangjchandler/laravel-helpers

Usage

user

Returns the current user, or null depending on authentication status.

This function assumes that your User model is found inside of app/Models and will not be registered if that class doesn't exist.

$user = user();

route_is

Check if the current route name matches the provided string.

route_is('dashboard.index');

authorize

Identical to Laravel's $this->authorize() method provided by the AuthorizesRequests trait.

public function index()
{
    authorize('viewAny', Post::class);
}

attributes() and @attributes

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>

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

A collection of helper functions that I use across my projects.

License:MIT License


Languages

Language:PHP 100.0%