ptuchik/core-utilities

Laravel 的核心工具,用于扩展一些功能并为其他相关包的项目做准备

1.0.42 2024-04-05 09:13 UTC

README

此包包含一些对 Laravel 5.5+ 有用的工具,用于扩展一些功能并为其他相关包的项目做准备

目前包含

  • class AbstractTypes - 扩展此类并添加您自己的常量,以便稍后轻松使用。

用法

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 - 仅过滤并允许来自 Google AppEngine 的 CRON 的请求的中介层

用法

只需将其添加到您需要过滤的路由中

  • class ForceSSL - 将 HTTP 请求转换为 HTTPS 的中介层(如果配置中已设置)

用法

编辑配置文件中的 protocol 参数并将其添加到您需要转换的路由中

  • class Handler - 将异常转换为 RESTful 错误消息的转换器

用法

从此类扩展您的 App/Exceptions/Handler,您将获得所有异常的 RESTful API 格式化

  • class Model - 此类从原生 Eloquent 模型扩展并添加了一些有用的功能,例如 camelCase 属性、可翻译属性以及可选和可配置的属性清理

用法

从此类扩展所有您的模型,而不是原生 Illuminate\Database\Eloquent\Model,您将自动获得它们

  • trait HasParams - 您可以在所有具有数据库中 params 属性的模型中使用此特质

不要忘记 在使用此特质之前将 params 属性转换为 array

  • trait HasIcon - 您可以在所有具有图标的模型中使用此特质。这将添加 $model->saveIcon($image);$model->deleteIcon(); 方法。

不要忘记 在使用此特质之前将 icon 列添加到您模型表之前

  • class Storage - 您可以用它作为您存储的工厂

用法

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...