Download the PHP package zvermafia/larastate without Composer

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

Larastate — a main source for your entity states values

Latest Version on Packagist Build Status Coverage Status Quality Score Total Downloads

Easy access to entity states values and to their localizations.

Navigation by sections

Introduction

The problem

When you have an entity with some states you usually need to access to those states' values and to their localizations. Let's consider the following cases:

Let's assume we have a User entity with a role state. And the role state can only accept 'member', 'moderator' and 'administrator' values.

And yes when you hardcoded those values in different places of your project then it will be harder to change (add, remove, rename) those values. Because you don't use a main source for those values.

A solution

Unfortunately Laravel doesn't provide a solution for this problem out of the box. So I've created this package. With this package you will not have problems in the above section! Let's solve those problems in the appropriate order.

Firstly create a States folder in the app directory, then create a UserState class in it with extending a StateAbstract abstract class. And define a ROLE constant in the class with those values from the above section. You should have something below:

Install

To install the package just pull it via composer and you're ready to setup.

Setup

The package have some convention about structuring a state classes directory, naming those classes and naming constants. But all this can be changed to suit your needs by extending a StateAbstract abstract class. So if you need it then take a look at the source code.

Let's assume we want to setup a state class for a post entity, so our steps are follows:

  1. Create a States folder in the app directory;
  2. Create a PostState.php file and put it into the app/States directory;
  3. Extend a StateAbstract abstract class and define constants, you should have something below:

  4. Create localization file in a resources/lang/en/entities directory with the entity name, so in our case it will be post.php . It's a regular Laravel's localization file but by default all state localizations should be grouped in a state key of the array. So you should have something like below:

Usage

For usage example we will use our PostState which we created it in the above section.

There are three cases and all works through PHP's magic __call() method:

  1. Getting values for the state
  2. Getting values with locales for the state
  3. Getting a locale for one of the state's values

All methods start with prefix get and ends with one of the case names (Values, ValuesWithLocales or Locale). And between those prefix and postfixes you should write your state name in StudlyCase format.

For a type state those will be:

  1. getTypeValues()
  2. getTypeValuesWithLocales()
  3. getTypeLocale(1)

Alternatives

So why I've created this package when there is already such kind of packages? Because they are a bit complicated for my simple task.

Change log

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

Testing

Contributing

Please see CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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


All versions of larastate with dependencies

PHP Build Version
Package Version
Requires php Version ~7.2
illuminate/support Version ^6.0 || ^7.0 || ^8.0
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 zvermafia/larastate contains the following files

Loading the files please wait ....