Download the PHP package jiannei/laravel-enum without Composer

On this page you can find all versions of the php package jiannei/laravel-enum. 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-enum

laravel-enum

A simple and easy-to-use enumeration extension package to help you manage enumerations in your project more conveniently, supporting Laravel and Lumen.

  • 一个简单好用的枚举扩展包,帮助你更方便地管理项目中的枚举,支持 Laravel 和 Lumen。

Tests Coverage Laravel Pint Pest Larastan Latest Stable Version Total Downloads Monthly Downloads License

中文文档 | English

介绍

laravel-enum 主要用来扩展项目中的枚举使用,通过合理的定义枚举可以使代码更加规范,更易阅读和维护。

php8.1 版本后内置枚举支持,更多信息可以查看:https://www.php.net/manual/zh/language.enumerations.php

参与社区讨论:- 教你更优雅地写 API 之「枚举使用」

概览

安装

支持 Laravel 10 以上版本:

使用

更为具体的使用可以查看测试用例:https://github.com/Jiannei/laravel-enum/tree/main/tests

常规使用

基础使用

枚举校验

枚举实例化

枚举实例化以后可以方便地通过对象实例访问枚举的 name、value 以及 description 属性的值。

枚举比较

枚举位置和导航

数组转换

多语言描述

枚举支持多语言描述,通过 description() 方法获取:

错误处理

当使用无效的名称或值时,会抛出详细的错误信息:

实际应用示例

枚举转换和校验

Model 中的枚举转换

API 参考

静态方法

方法 返回类型 描述
names() array<string> 获取所有枚举名称
values() array<int\|string> 获取所有枚举值
count() int 获取枚举数量
hasName(string $name) bool 检查是否包含指定名称
hasValue(mixed $value) bool 检查是否包含指定值
fromName(string $name) static 通过名称实例化
fromValue(mixed $value) static 通过值实例化
guess(mixed $value) static 智能猜测实例化
random() static 获取随机枚举实例
toArray(?string $localizationGroup = null) array 转换为详细数组
toSelectArray(?string $localizationGroup = null) array 转换为选择数组

实例方法

方法 返回类型 描述
name() string 获取枚举名称
value() int\|string 获取枚举值
description(?string $localizationGroup = null) string 获取描述
is(BackedEnum $enum) bool 检查是否等于指定枚举
isNot(BackedEnum $enum) bool 检查是否不等于指定枚举
isAny(BackedEnum ...$enums) bool 检查是否为任意指定枚举
isFirst() bool 检查是否为第一个枚举
isLast() bool 检查是否为最后一个枚举
next() ?static 获取下一个枚举
previous() ?static 获取上一个枚举

License

MIT


All versions of laravel-enum with dependencies

PHP Build Version
Package Version
No informations.
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 jiannei/laravel-enum contains the following files

Loading the files please wait ...