Download the PHP package elhareth/laravel-eloquent-metable without Composer

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

Laravel-Eloquent-Metable

Laravel-Eloquent-Metable is a package for extending laravel Eloquent models without messing up with the database schema.

Example Usage

Adding metadata to an eloquent model

Query scope to fetch model by it's metadata

Get attached metadata

Installation

Add the package to your Laravel app using composer

Run the migrations to add the required table to your database.

Add the Elhareth\LaravelEloquentMetable\IsMetable trait to any eloquent model class that you want to be able to attach metadata to.

Documentation

Handling Meta

The IsMetable trait will add metalist() method to your model, which meant to handle the realtion between your model and the meta data model Metable.

Attaching MetaData

Attach meta to a model with the setMeta() method. The method accepts three arguments: a string to use as a meta name, a value and additionally a string for group. The value argument will accept a number of different inputs, which will be converted to a string for storage in the database.

If you want to add many meta records you may pass an array as first parameter

Also you pass a second param as meta data group

Be Carefull !

if you adding a meta record with value of type array if it has value/group key it will be treated as $value / $group params, so when you adding an array that may have these keys consider using setMeta() method where the value param is treated as value no matter what it does contain.

Retrieving MetaData

You can retrieve the value of the meta at a given key with the getMeta() method.

The method getMeta accepts three arguments; getMeta(name: $name, default: $default nullable $nullable) The first the name of meta record The second parameter to specify a default value to return if no meta has been set at that key. The third parameter is a boolean to set whether to treat null values as not found

You may retrieve a collection of meta depending on specifec group

Checking For Presence of MetaData

You can check if a value has been assigned to a given key with the hasMeta() method. This method will return true if a record is found on database. You may pass another boolean value to control how to treat null values.

Queued Metables

You may mass assign metables and they will be attached once the model is created

Pre Metables

You may define default metables for each model and they'll be added once the model is created.

To do so you should implement Elhareth\LaravelEloquentMetable\IsMetableInterface> And define a method defaultMetables() which returns an array of metables you want to automatically attach to your model.

You can get list of model default metables by getDefaultMetables().

Deleting MetaData

To remove the meta stored at a given key, use removeMeta().

To delete all meta records from a model, use deleteMetaRecords().

Attached meta is automatically purged from the database when a IsMetable model is manually deleted. Metaable will not be cascaded if the model is deleted by the query builder.

Eager Loading MetaData

When working with collections of IsMetable models, be sure to eager load the meta relation for all instances together to avoid repeated database queries (i.e. N+1 problem).

Eager load from the query builder:

Lazy eager load from an Eloquent collection:

You can also instruct your model class to always eager load the meta relationship by adding 'metalist' to your model's $with property.

Querying Meta

The IsMetable trait provides a number of query scopes to facilitate modifying queries based on the meta attached to your models

Checking for Presence of a key

To only return records that have a value assigned to a particular key, you can use whereHasMeta(). You can also pass an array to this method, which will cause the query to return any models attached to one or more of the provided keys.

You can also query for records that does not contain a meta key using the whereDoesntHaveMeta(). Its signature is identical to that of whereHasMeta().

You can restrict your query based on the value stored at a meta key. The whereMeta() method can be used to compare the value using any of the operators accepted by the Laravel query builder's where() method.

The whereMetaIn() method is also available to find records where the value is matches one of a predefined set of options.

License

This package is released under the MIT license (MIT).


All versions of laravel-eloquent-metable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
illuminate/collections Version ^10.0
illuminate/contracts Version ^10.0
illuminate/database Version ^10.0
illuminate/support Version ^10.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 elhareth/laravel-eloquent-metable contains the following files

Loading the files please wait ....