Download the PHP package thinktomorrow/dynamic-attributes without Composer

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

Dynamic attributes

This small package adds nosql-like storage behaviour to your eloquent model. It allows the model to interact with json column values as if they were top-level attributes.

Installation

You can install the package via composer:

Setup

Here's the quick how to on setting up the package. We'll assume you already have an eloquent model set up.

  1. Add a json column to the database scheme of your eloquent model. By default, it should be named values.
  2. Add the HasDynamicAttributes trait to your eloquent model.
  3. Add a dynamicKeys property on the model and fill it with the value keys that should be stored and fetched from the json column.

Here's an example setup:

A json column

Behind the scenes the values are automatically transposed to and from the json attribute. On the model, no custom eloquent cast is needed, because the trait itself will handle the conversion to and from the stored value.

The dynamic attributes are preferably stored as a json database column but a string typed column should also be fine. The json column will just make your life easier when you need to query the database.

By default, the database column name is assumed to be values. You are free to change this.

Usage

Setting a value: setDynamic(string $key, $value)

The value can be set just like you're used to with any other eloquent attribute. There's a setDynamic($key, $value) method which allows you to explicitly set a dynamic attribute.

Getting a value: dynamic(string $key)

The value can be retrieved like a regular attribute. You can use the dynamic($key) method to retrieve the dynamic attribute value as well.

Checking a value: isDynamic()

Checks if the passed key refers to a dynamic attribute key or not.

Raw values

You can get the raw array of dynamic values via the rawDynamicValues method.

Localization

Dynamic attributes are built with localization in mind.

Setting a localized value is done by passing the locale as a nested key:

Retrieve the localized value:

An extra thing you can do is to add a dynamicLocales property on your model. This is an array and should contain all the locales of the model. This ensures you return an null value in case a localized value isn't found instead of the entire value array itself.

Changing the database column name

By default the column name is set to values. You can change this by overriding the dynamicDocumentKey in your model and returning your custom column/attribute name.

Eloquent method inheritance

The trait class overrides some eloquent methods. These methods are: getAttribute, setAttribute, setRawAttributes and removeTableFromKey. This is because of the integral connection with eloquent attribute logic and the way eloquent allows for behavioural change via inheritance.

If you use another trait that also overrides one of these methods, you're gonna bump into a method collision and need to alias the trait methods.

Other solutions

There's another great package that provides a similar functionality and that's spatie/laravel-schemaless-attributes. It also provides a nosql-like behaviour for json columns but takes a different approach. The main difference is that our package allows to work with top-level attributes and localized values, which was a requirement for some of our projects. With the package from Spatie, on the other hand, you can add multiple 'nosql' columns, which is currently not possible with our package.

Testing

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 dynamic-attributes with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-json Version *
illuminate/database Version ^8.12|^9.0|^10.0
doctrine/dbal Version ^3.1
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 thinktomorrow/dynamic-attributes contains the following files

Loading the files please wait ....