2017 © Pedro Peláez
 

library laravel-trait-pack

A basic collection of some useful traits for Laravel

image

silvertipsoftware/laravel-trait-pack

A basic collection of some useful traits for Laravel

  • Friday, February 26, 2016
  • by info@silvertipsoftware.com
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1,493 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 11 % Grown

The README.md

laravel-trait-pack

A basic collection of some useful traits for Laravel 5., (*1)

Overview

Most traits are configurable, and have standardized on a way of storing these config parameters without polluting the property names within the using class., (*2)

Trait config parameters are stored in a $traitConfigs static property. This is an associative array, where keys are defined by the trait. The ones in this pack use the fully qualified name of the trait, but that is not enforced., (*3)

For example,, (*4)

    $traitConfig = [
        'SilvertipSoftware\LaravelTraitPack\HasActiveState' => [ 'field' => 'flag' ]
    ];

HasActiveState

Adds an isActive method and a scope to a Laravel Model. The underlying field name is configurable, and defaults to active., (*5)

Example Config

    $traitConfig = [
        'SilvertipSoftware\LaravelTraitPack\HasActiveState' => [ 'field' => 'flag' ]
    ];

UsesAlternateConnection

Allows configurable connection names per class, or class hierarchies. Particularly useful for libraries. The connection name can either be defined directly on the class using:, (*6)

    $traitConfig = [
        'SilvertipSoftware\LaravelTraitPack\UsesAlternateConnection' => [ 'connection' => 'other_db' ]
    ]

or within a config file, under the database.alternateConnections tag., (*7)

    'alternateConnections' => [
        'FullyQualifiedClassname' => 'other_db',
        'AnotherClassName' => 'some_other_connection'
    ]

Classnames are searched up the hierarchy, so just the base class name can be specified in the config file. Defaults to null, or the default connection name., (*8)

ValidatesTrait

Adds an isValid method to a model, with a configurable set of rules. Rules are specifed with the rules trait config parameter. Additional rules can be specified with the creation_rules parameter., (*9)

Example

    $traitConfigs = [
        'SilvertipSoftware\LaravelTraitPack\ValidatesTrait' => [
            'rules' => [
                'name' => [ 'required', 'string', 'max:20' ],
                'age' => [ 'required', 'numeric', 'min:18' ]
            ],
            'creation_rules' => [
                'password' => [ 'required', 'string' ],
                'password_confirm' => [ 'required', 'string' ]
            ]
        ]
    ]

The $model->errors message bag is set with any validation errors., (*10)

The Versions

26/02 2016

dev-master

9999999-dev

A basic collection of some useful traits for Laravel

  Sources   Download

MIT

The Requires

 

02/11 2015

v1.0.0

1.0.0.0

A basic collection of some useful traits for Laravel

  Sources   Download

MIT

The Development Requires