All Projects → znck → plug

znck / plug

Licence: MIT license
A collection of pluggable traits for Eloquent (Laravel) models

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to plug

Laravel Migrate Fresh
An artisan command to build up a database from scratch
Stars: ✭ 179 (+1276.92%)
Mutual labels:  eloquent
Laravel Shareable Models
Create shareable links from your eloquent models.
Stars: ✭ 225 (+1630.77%)
Mutual labels:  eloquent
laratools
A collection of useful everyday tools for Laravel
Stars: ✭ 17 (+30.77%)
Mutual labels:  eloquent
Cms
Multilingual PHP CMS built with Laravel and bootstrap
Stars: ✭ 2,342 (+17915.38%)
Mutual labels:  eloquent
Slimcms
SlimCMS - lightweight CMS based on slim 3 framework
Stars: ✭ 201 (+1446.15%)
Mutual labels:  eloquent
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+21153.85%)
Mutual labels:  eloquent
Laravel Auditing
Record the change log from models in Laravel
Stars: ✭ 2,210 (+16900%)
Mutual labels:  eloquent
eloquent-filemaker
A Model extension and Eloquent driver for Laravel connecting to FileMaker through the Data API
Stars: ✭ 38 (+192.31%)
Mutual labels:  eloquent
Laravel Jit Loader
Stars: ✭ 210 (+1515.38%)
Mutual labels:  eloquent
laravel-attribute-observer
Observe (and react to) attribute changes made on Eloquent models.
Stars: ✭ 59 (+353.85%)
Mutual labels:  eloquent
Eloquent Hashids
On-the-fly hashids for Laravel Eloquent models. (🍰 Easy & ⚡ Fast)
Stars: ✭ 196 (+1407.69%)
Mutual labels:  eloquent
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (+1423.08%)
Mutual labels:  eloquent
eloquence
Eloquence provides a cache on top of Eloquent that prevents multiple models being created for a single database row using the Identity Map design pattern.
Stars: ✭ 18 (+38.46%)
Mutual labels:  eloquent
Larapoll
A Laravel package to manage your polls
Stars: ✭ 189 (+1353.85%)
Mutual labels:  eloquent
laravel-quasar
⏰📊✨Laravel Time Series - Provides an API to create and maintain data projections (statistics, aggregates, etc.) from your Eloquent models, and convert them to time series.
Stars: ✭ 78 (+500%)
Mutual labels:  eloquent
Eloquent Filter
The Eloquent Filter is a package for filter data of models by the query string. Easy to use and fully dynamic.
Stars: ✭ 175 (+1246.15%)
Mutual labels:  eloquent
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (+1730.77%)
Mutual labels:  eloquent
laravel-simplegrid
A simple component for generating powerful grids with Laravel.
Stars: ✭ 35 (+169.23%)
Mutual labels:  eloquent
inertiajs-tables-laravel-query-builder
Inertia.js Tables for Laravel Query Builder
Stars: ✭ 391 (+2907.69%)
Mutual labels:  eloquent
laravel-nestedupdater
Package for allowing updating of nested Eloquent model relations using a single nested data array.
Stars: ✭ 19 (+46.15%)
Mutual labels:  eloquent

Plug

A collection of pluggable Eloquent traits to enhance your Models.

Plug

StyleCI Status Build Status Coverage Status Software License Packagist Latest Version Issues

Installation

Either PHP 7.0+ is required.

To get the latest version of Plug, simply require the project using Composer:

$ composer require znck/plug

Instead, you may of course manually update your require block and run composer update if you so choose:

{
    "require": {
        "znck/plug": "^0.1"
    }
}

Once Plug is installed, you can use the plug[gable] traits.

Usage

All features of Plug are provided as traits, so you can directly put them in you model class. Traits would automatically boot. No configuration is required.

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use Znck\Plug\Eloquent\Traits\BelongsToThrough;

class User extends Model {
  use BelongsToThrough;
}

Best practice is to create an abstract model class and use required plugs(traits).

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use Znck\Plug\Eloquent\Traits\BelongsToThrough;
use Znck\Plug\Eloquent\Traits\FixBelongsTo;
use Znck\Plug\Eloquent\Traits\FixMorphTo;
use Znck\Plug\Eloquent\Traits\UuidKey;
use Znck\Plug\Eloquent\Traits\FixForeignKey;
use Znck\Plug\Eloquent\Traits\SelfDecorating;
use Znck\Plug\Eloquent\Traits\SelfValidating;

abstract class UUIDBaseModel extends Model
{
    use FixBelongsTo, FixMorphTo, BelongsToThrough, UuidKey, SelfValidating, SelfDecorating, FixForeignKey;

    public $incrementing = true; // Explained below.
}

Traits

  1. BelongsToThrough
    Inverse of HasManyThrough relation is missing from Eloquent. This plug (trait) provides belongsToThrough relationship. Under the hood, it uses BelongsToThrough from [znck/belongs-to-through] package.

  2. FixBelongsTo
    To maintain expected behavior of belongsTo relation, Eloquent has introduced a bug. If model has non-incrementing primary key (ex: UUID) and belongsTo relation value is null, then if it is eager loaded, it would die due to SQL error. Issue 12051

  3. FixForeignKey
    Eloquent has misleading behavior when guessing foreign key field name. It takes lowercase singular name of model class and appends _id to it, which is very counter-intuitive. Expected behavior is that it should guess foreign key field name from table name. Issue 10724

  4. FixMorphTo
    Relation class MorphTo inherits BelongsTo, so it is prone to same bug.

  5. SelfDecorating @deprecated
    It keeps database entries clean. For example: values in name column should start with uppercase letter.

  6. SelfValidating @deprecated in favour of znck/repository
    It validates attributes before saving or updating, hence only valid data goes in database.

  7. UuidKey
    It allows to usage of non-incrementing UUID primary keys.

class User extends Model {
  use UuidKey;
  // Make sure to set $incrementing to false.
  public $incrementing = false;
}

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email :author_email instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].