Download the PHP package klaude/eloquent-preferences without Composer

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

Preferences for Laravel Eloquent models

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Use this library to bind multiple key/value pair preferences to your application's Eloquent models. Preferences are stored in your application's database so they can be easily stored and queried for. This library supports Eloquent 5 through 8 installed either standalone or as a part of the full Laravel framework. Issues and pull requests are welcome! See CONTRIBUTING.md for more information.

Installation

Run composer require klaude/eloquent-preferences to download and install the library.

Configuring In Laravel

1) Add EloquentPreferencesServiceProvider to config/app.php:

2) Install the configuration and database migration files:

3) Model preferences are stored in the "model_preferences" database table by default. If you would like to use a different table then edit the "table" entry in config/eloquent-preferences.php.

4) Install the model preferences database:

Configuring Without Laravel

1) Model preferences are stored in the "model_preferences" database table by default. If you would like to use a different table then define the MODEL_PREFERENCE_TABLE constant at your project's point of entry with your preferred table name.

2) Install the model preferences database. There are a number of ways to do this outside of Laravel. Here's the schema blueprint to apply:

Usage

Add the HasPreferences trait to the Eloquent models that you would like to have related preferences.

This builds a polymorphic has-many relationship called "preferences" that you can query on your model like any other Eloquent relationship. Model preferences are modeled in the KLaude\EloquentPreferences\Preference class. A preference object has preference, value, and Eloquent's built-in created_at and updated_at attributes. The HasPreferences trait can be used by any number of model classes in your application.

Eloquent queries can be run directly on the Preference class as well.

Helper Methods

The HasPreferences trait has a number of helper methods to make preference management a little easier.

Retrieving Preferences

Call the getPreference($preferenceName) or prefers($preferenceName) methods to retrieve that preference's value.

Setting Preferences

Call the setPreference($name, $value) or setPreferences($arrayOfNamesAndValues) methods to set your model's preference values. Setting a preference either creates a new preference row if the preference doesn't exist or updates the existing preference with the new value.

Removing Preferences

Call the clearPreference($preferenceName), clearPreferences($arrayOfPreferenceNames), or clearAllPreferences() methods to remove one, many, or all preferences from a model. Clearing preferences removes their associated rows from the preferences table.

Default Preference Values

By default, getPreference() and prefers() return null if the preference is not stored in the database. There are two ways to declare default preference values:

1) Use an optional second parameter to getPreference() and prefers() to define a default value per call. If the preference is not stored in the database then the default value is returned.

2) Avoid requiring extra parameters to every getPreference() and prefers() call by declaring a protected $preference_defaults array in your model containing a key/value pair of preference names and their default values. If the preference is not stored in the database but is defined in $preference_defaults then the value in $preference_defaults is returned. If neither of these exist then optional default value parameter or null is returned.

Please note default preference values only apply when using the getPreference() and prefers() methods. Default values are not honored when retrieving preferences by Eloquent query.

Casting Preference Values

Preferences are stored as strings in the database, but can be cast to different types when retrieved.

Declare a protected $preference_casts array in your model containing a key/value pair of preference names and the types to cast their values to. Preferences are stored and cast according to the same rules as Eloquent's attribute type casts.

As with default values, casting preferences is only performed when using the getPreference(), prefers(), setPreference(), and setPreferences() helper methods.

Hidden Preference Attributes

By default all preference model attributes are visible when exporting to JSON. However it is possible to declare hidden attributes that act in the same manner as Eloquent's hidden attributes. There are two ways to declare which preference attributes to hide from JSON export:

1) If this library is being used in a Laravel project then declare hidden attributes in the "hidden-attributes" key in config/eloquent-preferences.php.

2) If this library is being used outside the Laravel framework then define the MODEL_PREFERENCE_HIDDEN_ATTRIBUTES constant at your project's point of entry with a comma-separated list of attributes to hide from JSON export.


All versions of eloquent-preferences with dependencies

PHP Build Version
Package Version
Requires ext-json Version *
illuminate/database Version ~5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0
illuminate/support Version ~5|~6.0|~7.0|~8.0|~9.0|~10.0|~11.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 klaude/eloquent-preferences contains the following files

Loading the files please wait ....