Download the PHP package mmanos/laravel-metable without Composer

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

Meta Package for Laravel 4

This package adds meta support to your Laravel application. You can configure it to attach meta to any of your existing Eloquent models.

Installation

Composer

Add this to your composer.json file, in the require object:

After that, run composer install to install the package.

Service Provider

Register the Mmanos\Metable\MetableServiceProvider in your app configuration file.

Configuration

Metas Migration and Model

First you'll need to publish a metas table and a Meta model. This table will hold a summary of all meta created by your metable models.

Note: Modify the last parameter of this call to change the table/model name.

Note: You may publish as many meta tables as you need, if you want to keep the meta separate for different types of content, for example.

Metable Migration

Next, publish a migration for each type of content you want to attach meta to. You may attach meta to as many types of content as you wish. For example, if you want to be able to add meta to both a users table and a blog_posts table, run this migration once for each table.

Run Migrations

Once the migration has been created, simply run the migrate command.

Model Setup

Next, add the Metable trait to each metable model definition:

Then you need to specify the meta model as well as the metable table to use with your model:

Syncing Custom Attributes

Sometimes you will want to have some of the same fields in your content table synced to the metable table records. This will allow you to filter and sort by these attributes when querying the metable table. Luckily this system will automatically sync any fields you define to the metable table records any time there are changes.

To get started, modify the metable migration file to include your additional fields.

Then, tell your model which fields it needs to sync:

Now every time you create or update a model, these fields will by synced to all metable table records for the piece of content.

Syncing Deleted Content

This package will automatically delete all metable table records for a piece of content when that piece of content is deleted.

If you are using the SoftDeletingTrait and you are syncing the deleted_at column to your metable table records, this package will automatically soft-delete all metable table records for a piece of content when that piece of content is deleted. If the content is restored, then the metable table records are restored as well.

Working With Meta

Setting Content Meta

To set a meta value on an existing piece of content:

Or set multiple metas at once:

Note: If a piece of content already has a meta the existing value will be updated.

Unsetting Content Meta

Similarly, you may unset meta from an existing piece of content:

Or unset multiple metas at once:

Note: The system will not throw an error if the content does not have the requested meta.

Checking for Metas

To see if a piece of content has a meta:

Retrieving Meta

To retrieve a meta value on a piece of content, use the meta method:

Or specify a default value, if not set:

You may also retrieve more than one meta at a time and get back an array of values:

Retrieving All Metas

To fetch all metas associated with a piece of content, use the metas relationship:

Retrieving an Array of All Metas

To fetch all metas associated with a piece of content and return them as an array, use the metasArray method:

Querying for Content from Meta

Performing Queries

Now let's say you want to query for all content that has a given meta:

Or optionally specify the meta value to match:

Or optionally specify the meta value and operator to match:

These queries extend the same QueryBuilder class that you are used to working with, so all of those methods work as well:

Note: The update and delete methods on a QueryBuilder object do not work for these queries.

You may query for content that has any of the given meta:

Or query for content that has any of the given meta that matches the given values:

Note: Query performance can be reduced for the withAnyMeta and whereAnyMeta queries if your queries match thousands of records or more.

And you may combine multiple filters:

Meta Contexts

Sometimes you might want to associate your metas (summary) table records with some custom context for your application. For example, say you have a companies table and a users table and each user belongs to a company. And now you also want to associate each meta record with a company allowing you to fetch all meta used by each individual company. In order to do so, we have to tell this package to be aware of this company context and modify it's queries accordingly.

To get started, make sure you modify your metas migration to include any context fields (company_id, in this case). You might also need to update the unique index, if necessary.

Then modify your metable model by adding a metaContext method:

Next modify your Meta model (or whatever name you specified during configuration) to apply any contexts:

The applyQueryContext method will adjust any meta queries used by this package to filter on company_id.

The applyModelContext method is called when creating a new Meta record and should set any required context fields.

Finally, when performing queries, specify the context to apply:


All versions of laravel-metable with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/support Version ~4.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 mmanos/laravel-metable contains the following files

Loading the files please wait ....