承接 everully/laravel-enum-on-steroids 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

everully/laravel-enum-on-steroids

最新稳定版本:v0.2.0

Composer 安装命令:

composer require everully/laravel-enum-on-steroids

包简介

This package provides Enum trait to speed up the development of Laravel applications.

README 文档

README

This package provides Enum trait to speed up the development of Laravel applications.

Requirements

  • Laravel 9.0 or later.
  • PHP 8.1 or later.

Installation

Install via composer:

composer require everully/laravel-enum-on-steroids

Usage

Add the EnumOnSteroids trait to your Enum class to add some useful methods.

use Everully\LaravelEnumOnSteroids\EnumOnSteroids;

enum StringEnum: string
{
    use EnumOnSteroids;

    case A = 'a';
    case B = 'b';
    case C = 'c';
}

Available methods

Equals

Check if the enum is equal to another enum or a string.

StringEnum::A->equals(StringEnum::A); // true

StringEnum::A->equals('a'); // true

StringEnum::A->equals(AnotherEnum::A); // false

StringEnum::A->equals('d'); // false

Values

Return an array all the values of the enum.

StringEnum::values(); // ['a', 'b', 'c']

Names

Return an array of all the names of the enum.

StringEnum::names(); // ['A', 'B', 'C']

Collection

Return a Laravel collection of all the values of the enum.

StringEnum::collection();
// Illuminate\Support\Collection<StringEnum>

Collect

Return a Laravel collection of all the values of the enum.

StringEnum::collect(['a', 'b', 'c']);
// Illuminate\Support\Collection<StringEnum>

StringEnum::collect([StringEnum::A, StringEnum::B, StringEnum::C]);
// Illuminate\Support\Collection<StringEnum>

If provided string or object is not a valid enum value, the collection will not contain it.

StringEnum::collect(['a', 'invalid']);
// Only contains 'a'

StringEnum::collect([StringEnum::A, AnotherEnum::B]);
// Only contains 'a'

Has

Returns true if the enum has the provided value.

StringEnum::has('a'); // true
StringEnum::has(StringEnum::A); // true
StringEnum::has('invalid'); // false
StringEnum::has(AnotherEnum::A); // false

Has any

Returns true if the enum has any of the provided values.

StringEnum::hasAny(['a', 'invalid']); // true
StringEnum::hasAny([StringEnum::A, AnotherEnum::A]); // true
StringEnum::hasAny(['invalid', 'invalid2']); // false
StringEnum::hasAny([CopyStringEnum::A, CopyStringEnum::A]); // false

Has all

Returns true if the enum has all the provided values.

StringEnum::hasAny(['a', 'b']); // true
StringEnum::hasAny([StringEnum::A, AnotherEnum::A]); // true
StringEnum::hasAny(['a', 'invalid']); // false
StringEnum::hasAny([StringEnum::A, CopyStringEnum::A]); // false

统计信息

  • 总下载量: 139
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固