Git Product home page Git Product logo

laravel-metable's Introduction

Laravel-Metable

Coveralls StyleCI Packagist

Laravel-Metable is a package for easily attaching arbitrary data to Eloquent models.

Features

  • One-to-many polymorphic relationship allows attaching data to Eloquent models without needing to adjust the database schema.
  • Type conversion system allows data of numerous different scalar and object types to be stored and retrieved. See the documentation for the list of supported types.

Example Usage

Attach some metadata to an eloquent model

$post = Post::create($this->request->input());
$post->setMeta('color', 'blue');

Query the model by its metadata

$post = Post::whereMeta('color', 'blue');

Retrieve the metadata from a model

$value = $post->getMeta('color');

Installation

  1. Add the package to your Laravel app using composer
composer require plank/laravel-metable
  1. Register the package's service provider in config/app.php. In Laravel versions 5.5 and beyond, this step can be skipped if package auto-discovery is enabled.
'providers' => [
    ...
    Plank\Metable\MetableServiceProvider::class,
    ...
];
  1. Publish the config file (config/metable.php) of the package using artisan.
php artisan vendor:publish --provider="Plank\Metable\MetableServiceProvider"
  1. Run the migrations to add the required table to your database.
php artisan migrate
  1. Add the Plank\Metable\Metable trait to any eloquent model class that you want to be able to attach metadata to.

Note: If need a more generic way to reference different Metable Model classes, you can optionally apply the Plank\Metable\MetableInterface to your models.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Plank\Metable\Metable;

class Post extends Model
{
    use Metable;

    //...
}

Documentation

The full documentation is available on ReadTheDocs.

License

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

About Plank

Plank is a web development agency based in Montreal, Canada.

laravel-metable's People

Contributors

frasmage avatar geosot avatar squatto avatar luukvdo avatar alexdemers avatar braunson avatar leocolomb avatar saulens22 avatar tormjens avatar aneesdev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.