Download the PHP package custom-d/laravel-helpers without Composer

On this page you can find all versions of the php package custom-d/laravel-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-helpers

Latest Release coverage report Github Issues For Laravel 5 Total Downloads Latest Stable Version License

Laravel Helpers

Collection of helpers for re-use accross a few of our projects

Installation

Install via composer

Upgrade V2 to V3

By using the CustomD\LaravelHelpers\Models\Policies\CrudPermissions trait in your model policy alongside Spatie role permissions you can avoid having to write lots of boilerplate methods in your policy file.

Instead of a Policy like this

it would now look as follows:

and it will automatically check for the following permissions which you would have seeded / set up in Spatie's package.

Additionally if using the PermissionBasedAccess trait on your model, the following extra ones are taken into account

If the user_id column is not user_id, set that in the getOwnerKeyColumn method documented below in the Crud Access for Model section.

viewAny, create, restore & forceDelete will use the base versions only, and you would need to customise if needed yourself by setting up the permission or policy method to deal with it based on your business logic. Create and viewAny do not have Ownership within a default policy, and the restore / forceDelete are mainly only an administrative functionality.

Permission naming.

The permission naming will by default use a plural of the model name: ie User becomes users / BlogPost becomes blog_posts

Crud Access Permission Global Trait & Scope for Model

If you use the CustomD\LaravelHelpers\Traits\PermissionBasedAccess trait on your model it will look for the following Spatie permissions by default:

xxx.view, xxx.viewOwn

This works as follows:

To modify the user column, add this to the model.

to call without the scopes: use the withoutPermissionCheck modifier: eg Model::withoutPermissionCheck()->get()

Helpers

execute - this helper runs an execute action on an action file with dependancy injection on the contructor

If you discover any security related issues, please email instead of using the issue tracker.

String Helpers

isEmail -- usage Str::isEmail('xxx') or str('xxx')->isEmail() -- will return boolean.

Array Helpers

pushBefore - will push one or more items before the specified key, or append to the end of the array if the key does not exist: PushAfter will push one or more items after the specified key

Collection Helpers

pushBefore - will push one or more items before the specified key, or append to the end of the array if the key does not exist: PushAfter will push one or more items after the specified key

DB Macros

Null Or Empty

when dealing with some of our legacy databases we have some columns where the entry is either null or empty and these macros allow you to query this without the double entries:

Case insensitive statments

Enforced Non Nullable Relations (orFail chain)

DB Repositories

use of repositories via extending the CustomD\LaravelHelpers\Repository\BaseRepository abstract example in the UserRepository.stub.php file

Observerable trait (Deprecated)

adding this trait to your models will automatically look for an observer in the app/Observers folder with the convension {model}Observer as the classname,

you can additionally/optionally add

to add a additional ones if

Replace this with

Record or Fake HTTP Calls

The RecordsOrFakesHttpCalls trait will allow you to record or fake http calls in your tests. This is useful for testing external api calls without actually calling them.

Add the trait to your PHPUnit test file, ensure the tests/stubs/ directory exists, and then wrap your test code in a callable:

Date Manipulation

You can set user timezones via the following options:

  1. optionally create a migration with:

  2. in user model:

Additionally you can set defaults on the timezone via the attributes method or a setter or even in the migration.

  1. in your app config file add the user_timezone parameter.

  2. add the UserTimeZone middleware to your api middleware list.

You can now access the current requests timezone via config('request.user.timezone')

Date(Carbon) Helpers attached to above:

methods available:

You can also use the CDCarbonDate to create a few different date objects.

Value Objects

Example:

Or using attributes to make advanced objects.

Best practice is to use the make option, which will validate, if you use a public constructor it will not.

These should all be marked as READONLY and FINAL.

The attributes available are:

Mapping Valueobject from your Request would be as easy as doing one of the following:

As we are using final classes, these are immutable, if you need a cloned copy with edited values you can use the put command to create a new value object: eg:

Larastan Stubs

these are temporary only till implemented by larastan

add to your phpstan.neon.dist file

Filament Plugin

this is only if you want to deal with user timezones for display, else will be in UTC in the Filament panel

simply add to your panelProvider ->plugin(UserTimeZonePlugin::make())

Credits


All versions of laravel-helpers with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/notifications Version ^9.0|^10.0|^11.0
illuminate/support Version ^9.0|^10|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package custom-d/laravel-helpers contains the following files

Loading the files please wait ....