Download the PHP package spatie/laravel-enum without Composer

On this page you can find all versions of the php package spatie/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?
spatie/laravel-enum
Rate from 1 - 5
Rated 1.00 based on 1 reviews

Informations about the package laravel-enum

Laravel support for spatie/enum

Latest Version on Packagist License Postcardware

Build Status Total Downloads

This package provides extended support for our spatie/enum package in Laravel.

Installation

You can install the package via composer:

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Usage

Model Attribute casting

Chances are that if you're working in a Laravel project, you'll want to use enums within your models. This package provides two custom casts and the \Spatie\Enum\Laravel\Enum also implements the \Illuminate\Contracts\Database\Eloquent\Castable interface.

By using the casts the casted attribute will always be an instance of the given enum.

Validation Rule

This package provides a validation rule to validate your request data against a given enumerable.

This rule validates that the value of status is any possible representation of the StatusEnum.

But you can also use the simple string validation rule definition:

If you want to customize the failed validation messages you can publish the translation file.

We pass several replacements to the translation key which you can use.

Request Data Transformation

A common scenario is that you receive an enumerable value as part of your request data. To let you work with it as a real enum object you can transform request data to an enum in a similar way to the model attribute casting.

Request macro

There is a request macro available which is the base for the other possible ways to cast request data to an enumerable.

This is an example definition of all possible request enum castings. There are three predefined keys available as constants on Spatie\Enum\Laravel\Http\EnumRequest to cast enums only in specific request data sets. All other keys will be treated as independent enum casts and are applied to the combined request data set.

You can call this macro yourself in every part of your code with access to a request instance. Most commonly you will do this in your controller action if you don't want to use one of the other two ways.

Form Requests

Form requests are the easiest way to cast the data to an enum.

The request data transformation is done after validation via the FormRequest::passedValidation() method. If you define your own passedValidation() method you have to call the request macro transformEnums() yourself.

Route Binding

Beside using form requests, you can also use route binding. Similar Laravel's Route Model Binding, it automatically inject enum instances into your route action.

Implicit Binding

To use implicit route binding, be sure add Spatie\Enum\Laravel\Http\Middleware\SubstituteBindings middleware. For example, add it in your app\Http\Kernel.php:

Use a type-hinted variable name that matches route segment to use implicit route binding.

Explicit Binding

To have an explicit binding, there is a Route::enum() macro. It's important that your route/group uses the \Illuminate\Routing\Middleware\SubstituteBindings middleware. This middleware is enabled by default for the web route group.

Enum Make Command

We provide an artisan make command which allows you to quickly create new enumerables.

You can use --method option to predefine some enum values - you can use them several times.

Faker Provider

It's very likely that you will have a model with an enum attribute and you want to generate random enum values in your model factory. Because doing so with default faker is a lot of copy'n'paste we've got you covered with a faker provider Spatie\Enum\Laravel\Faker\FakerEnumProvider. The static register() method is only a little helper - you can for sure register the provider the default way $faker->addProvider(new FakerEnumProvider).

The faker methods itself are inherited from the base packages Faker Provider.

Livewire

You can use an enum as a property on a Livewire component like this:

Just one thing is required to make this work: implement \Livewire\Wireable on all the enums you’ll be using with Livewire::

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-enum with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
illuminate/console Version ^8.0 || ^9.43 || ^10.0 || ^11.0
illuminate/contracts Version ^8.0 || ^9.43 || ^10.0 || ^11.0
illuminate/database Version ^8.0 || ^9.43 || ^10.0 || ^11.0
illuminate/http Version ^8.0 || ^9.43 || ^10.0 || ^11.0
illuminate/support Version ^8.0 || ^9.43 || ^10.0 || ^11.0
spatie/enum Version ^3.9
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 spatie/laravel-enum contains the following files

Loading the files please wait ....