Download the PHP package sukohi/metaphor without Composer

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

Metaphor

A Laravel package that allows you to manage metadata. This package is maintained under Laravel 5.8.

Installation

Run the following command.

composer require sukohi/metaphor:3.*

Preparation

1. Trait

Set MetaphorTrait in your model as follows.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Sukohi\Metaphor\MetaphorTrait;

class Item extends Model
{
    use MetaphorTrait;
}

2. Migration

Just run the migration command.

Note: You do NOT need to make any migrations by yourself because this package already has it.

php artisan migrate

That's it!

Usage

Save

$item = \App\Item::find(1);
$item->meta->key_1 = 300;
$item->meta->key_2 = 'yyy';
$item->meta->key_3 = ['item_1x', 'item_2', 'item_3'];
$item->meta->key_4 = null;
$item->meta->save();

Note: $item->meta is an extended Collection of Laravel.
So you can use all of the methods as usual.

Delete

$item->meta->delete($key);

// or

$item->meta->deleteAll();

Check if a meta value exists

if($item->meta->has($key)) {

    // has it!

}

About appending

If you'd like metadata to include in model data, set meta to $appends.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Sukohi\Metaphor\MetaphorTrait;

class Item extends Model
{
    use MetaphorTrait;
    protected $appends = ['meta'];  // <- here
}

Where clause

1. whereMeta

\App\Item::whereMeta('price', '500')->get();
\App\Item::whereMeta('price', 'LIKE', '%50%')->get();
\App\Item::orWhereMeta('price', '500')->get();
\App\Item::orWhereMeta('price', 'LIKE', '%50%')->get();

2. whereMetaIn

\App\Item::whereMetaIn('price', [300, 500])->get();
\App\Item::orWhereMetaIn('price', [300, 500])->get();

3. whereMetaNotIn

\App\Item::whereMetaNotIn('price', [300, 500])->get();
\App\Item::orWhereMetaNotIn('price', [300, 500])->get();

4. whereMetaNull

\App\Item::whereMetaNull('price')->get();
\App\Item::orWhereMetaNull('price')->get();

5. whereMetaNotNull

\App\Item::whereMetaNotNull('price')->get();
\App\Item::orWhereMetaNotNull('price')->get();

OrderByMeta

\App\Item::orderByMeta($key', 'asc')->get();
\App\Item::orderByMeta($key', 'desc')->get();

Note: This method uses FIELD(value, val1, val2, val3, ...) function in SQL.
It means if your DB system does not have the function, this feature is not available. MySQL has it, though.

License

This package is licensed under the MIT License.
Copyright 2019 Sukohi Kuhoh


All versions of metaphor with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ~5.8.13
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 sukohi/metaphor contains the following files

Loading the files please wait ....