ptuchik/core-utilities

Core utilities for Laravel to extend some functionality and prepare project for other related packages

1.0.42 2024-04-05 09:13 UTC

README

This package includes some useful utilities for Laravel 5.5+ to extend some functionality and prepare project for other related packages

Currently included:

  • class AbstractTypes - Extend this class and add your constants to use them later easily.

Usage

class Gender extends AbstractTypes {
    const MALE = 1;
    const FEMALE = 2;
}
    print_r(Gender::MALE); // Output: 1
    print_r(Gender::FEMALE); // Output: 2
    print_r(Gender::all()); // Output: '1,2'
    print_r(Gender::all('json')); // Output: '{"1":"translated.male","2":"translated.female"}'
    // You can also pass second parameter false, to not translate the values
    print_r(Gender::all('json', false)); // Output: '{"1":"MALE","2":"FEMALE"}'
    print_r(Gender::all('array')); // Output: ["MALE" => 1, "FEMALE" => 2]
  • class AppEngineCron - Just a middleware to filter and allow only requests from Google AppEngine's CRON

Usage

Just add to routes you need to filter

  • class ForceSSL - Middleware to convert HTTP reuests to HTTPS if set in configuration

Usage

Edit protocol parameter in configuration file and add to routes you need to convert

  • class Handler - Exception to RESTful error messages converter

Usage

Extend your App/Exceptions/Handler from this class, and you will get all exceptions prettified for RESTful API

  • class Model - This class extends from native Eloquent Model and adds some useful features like camelCase attributes, translatable attributes and optional and configurable attribute sanitization

Usage

Extend all your model's from this one instead of native Illuminate\Database\Eloquent\Model and you will get them all automatically

  • trait HasParams - You can use this trait in all your models which have params attribute in database

DO NOT FORGET to cast your params attribute as array before using this trait

  • trait HasIcon - You can use this trait in all your models which have icon. This will add $model->saveIcon($image); and $model->deleteIcon(); methods.

DO NOT FORGET to add icon column to your model's table before using this trait

  • class Storage - You can use it as a factory for your storage

Usage

use Ptuchik\CoreUtilities\Helpers\Storage;

$storage = new Storage(); // Pass true as the only parameter if you need to initialize your public storage

// ... after initialization you can use $storage variable as regular Filesystem Adapter. like:

$storage->get($path);
$storage->put($path);

// ...etc...