Download the PHP package awobaz/eloquent-mutators without Composer

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

Eloquent Mutators

Eloquent Mutators allows us to define accessors and mutators outside of an Eloquent model. This gives us the ability to organize and reuse them on any model or any attribute of the same model.

The problem

Eloquent has support for accessors and mutators. However, it requires us to define them directly in the model. What if we want to reuse an accessor/mutator logic in another model? Or, what if we want to reuse an accessor/mutator logic for another attribute of the same model? We can't! Eloquent Mutators aims at solving this limitation.

Related discussions:

Installation

The recommended way to install Eloquent Mutators is through Composer

The package will automatically register itself if you're using Laravel 5.5+. For Laravel 5.4, you'll have to register the package manually:

1) Open your config/app.php and add the following to the providers array:

2) In the same config/app.php add the following to the aliases array:

Note: Eloquent Mutators requires Laravel 5.4+.

After installation, publish the assets using the mutators:install Artisan command. The primary configuration file will be located at config/mutators.php. The installation also publishes and registers the app/Providers/MutatorServiceProvider.php. Within this service provider, you may register custom accessors/mutators extensions.

Usage

Using the Awobaz\Mutator\Database\Eloquent\Model class

Simply make your model class derive from the Awobaz\Mutator\Database\Eloquent\Model base class. The Awobaz\Mutator\Database\Eloquent\Model extends the Eloquent base class without changing its core functionality.

Using the Awobaz\Mutator\Mutable trait

If for some reasons you can't derive your models from Awobaz\Mutator\Database\Eloquent\Model, you may take advantage of the Awobaz\Mutator\Mutable trait. Simply use the trait in your models.

Syntax

After configuring your model, you may configure accessors and mutators for its attributes.

Defining accessors

For the following Post model, we configure accessors to trim whitespace from the beginning and end of the title and content attributes:

As you can see, we use an array property named accessors on the model to configure its accessors. Each key of the array represents the name of an attribute, and the value points to one or multiple accessors. To apply multiple accessors, pass an array as value (the accessors will be applied in the order they are specified):

Defining mutators

To define mutators, use an array property named mutators instead.

Note: The name of the properties used for accessors and mutators can be respectively configured in the config/mutators.php configuration file.

Defining accessors/mutators extensions

In the previous examples, we use accessors/mutators provided by the package. You may also register accessors/mutators extensions using the extend method of the Mutator facade. The extend method accepts the name of the accessor/mutator and a closure.

As you can see, the model ($model), the attribute's value ($value) and the attribute's name ($key) are passed to the closure, allowing you to access other attributes of the model to compute and return the desired value.

Additional parameters

You can also define additional parameters for an extension. This give us the flexibility to implement dynamic accessors/mutators.

In the above example, the model ($model), the attribute's value ($value), the attribute's name ($key) and two additional parameters are passed to the closure.

To apply this extension, we can use the following syntaxes:

This will replace every occurence of one with two for the content attribute.

Built-in accessors/mutators

lower_case

Convert the attribute to lower case.

upper_case

Convert the attribute to upper case.

capitalize

Convert the first character of attribute to upper case.

capitalize_words

Convert the first character of each word of the attribute to upper case.

trim_whitespace

Strip whitespace from the beginning and end of the attribute.

camel_case

Convert the attribute to camel case.

snake_case

Convert the attribute to snake case.

studly_case

Convert the attribute to studly case.

kebab_case

Convert the attribute to kebab case.

title_case

Convert the attribute to title case.

plural

Convert the attribute to its plural form (only supports the English language).

singular

Convert the attribute to its singular form (only supports the English language).

slug

Convert the attribute to its URL friendly "slug" form.

remove_extra_whitespace

Remove extra whitespaces within the attribute.

preg_replace:pattern,replacement[,limit]

Perform a regular expression search and replace on the attribute.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Unit Tests

In order to run the test suite, install the development dependencies:

Then, run the following command:

Authors

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.

Sponsored by

License

Eloquent Mutators is licensed under the MIT License.


All versions of eloquent-mutators with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1|^8.0
illuminate/database Version ~5.4|~6.0|~7.0|~8.0|~9.0|~10.0
illuminate/console Version ~5.4|~6.0|~7.0|~8.0|~9.0|~10.0
illuminate/support Version ~5.4|~6.0|~7.0|~8.0|~9.0|~10.0
illuminate/cache Version ~5.4|~6.0|~7.0|~8.0|~9.0|~10.0
laravel/helpers Version ^1.5
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 awobaz/eloquent-mutators contains the following files

Loading the files please wait ....