Enum Methods | enum | Spatie

 SPATIE

enum
====

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Enum](https://spatie.be/docs/enum/v2)  Usage  Enum Methods

 Version   v3   v2   v1

 Other versions for crawler [v3](https://spatie.be/docs/enum/v3) [v2](https://spatie.be/docs/enum/v2) [v1](https://spatie.be/docs/enum/v1)

  Enum Methods
- [ Introduction ](https://spatie.be/docs/enum/v2/introduction)
- [ Postcardware ](https://spatie.be/docs/enum/v2/postcardware)
- [ Installation and setup ](https://spatie.be/docs/enum/v2/installation-and-setup)
- [ Questions &amp; issues ](https://spatie.be/docs/enum/v2/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/enum/v2/changelog)
- [ About us ](https://spatie.be/docs/enum/v2/about-us)

Usage
-----

- [ Enum Setup ](https://spatie.be/docs/enum/v2/usage/enum-setup)
- [ Make Enum ](https://spatie.be/docs/enum/v2/usage/make-enum)
- [ Enum Methods ](https://spatie.be/docs/enum/v2/usage/enum-methods)
- [ Compare Enums ](https://spatie.be/docs/enum/v2/usage/compare-enums)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/enum                                                                                                                                                                                                                                    `

Enum Methods
============

###  On this page

1. [ \_\_toString() ](#content-tostring)
2. [ getIndex() ](#content-getindex)
3. [ getIndices() ](#content-getindices)
4. [ getValue() ](#content-getvalue)
5. [ getValues() ](#content-getvalues)
6. [ isAny() ](#content-isany)
7. [ isEqual() ](#content-isequal)
8. [ make() ](#content-make)
9. [ toArray() ](#content-toarray)

\_\_toString()
--------------------------------------------------------------------------------------

will return the enum value.

```
echo WeekDayEnum::make(1); // 'Montag'
```

getIndex()
----------------------------------------------------------------------------------

will return the enum index and could be overridden to customize the index.

```
WeekDayEnum::monday()->getIndex(); // 1
```

getIndices()
----------------------------------------------------------------------------------------

will return all indices available on the enum.

```
WeekDayEnum::getIndices(); // [1, 2, 3, 4, 5, 6, 7]
```

getValue()
----------------------------------------------------------------------------------

will return the enum value and could be overridden to customize the value.

```
WeekDayEnum::monday()->getValue(); // 'Montag'
```

getValues()
-------------------------------------------------------------------------------------

will return all values available on the enum.

```
WeekDayEnum::getValues(); // ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag']
```

isAny()
-------------------------------------------------------------------------

will return `true` if the enum is equal with any of the given - otherwise `false`.

```
WeekDayEnum::monday()->isAny(['monday', 0]); // true
```

isEqual()
-------------------------------------------------------------------------------

will return `true` if the enum is equal with the given - otherwise `false`.

```
WeekDayEnum::monday()->isEqual('tuesday'); // false
```

make()
----------------------------------------------------------------------

will return an instance of the enum - further details [make enum](/enum/v2/usage/make-enum).

toArray()
-------------------------------------------------------------------------------

will return an associative array with the value as key and the index as value.

```
WeekDayEnum::toArray(); // ['Montag' => 1, 'Dienstag' => 2, 'Mittwoch' => 3, 'Donnerstag' => 4, 'Freitag' => 5, 'Samstag' => 6, 'Sonntag' => 7]
```

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
