2017 © Pedro Peláez
 

library abstraction

Abstraction - Abstract

image

adamgoose/abstraction

Abstraction - Abstract

  • Thursday, November 14, 2013
  • by adamgoose
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Abstraction

Abstraction for Laravel is designed to in-source all of your model validation to the model itself., (*1)

Features

Abstraction does one thing: validate your models for you! Simply define the $rules variable on your model, and extend the Abstraction model, and you're good to go!, (*2)

Requirements

Abstraction is built for Laravel, specifically 4.0.*., (*3)

Installation

To install Abstraction, simply add "adamgoose/abstraction": "dev-master" to your composer.json, and execute composer update., (*4)

Usage

To utilize Abstraction on a model, extend Adamgoose\Abstraction\Model instead of Eloquent, like so:, (*5)

<?php

use Adamgoose\Abstraction\Model;

class Item extends Model {

}

Once you're extending Abstraction, you can simply add your validtion rules to the model, like so:, (*6)

  public static $rules = [
    // validation rules
    'name' => 'required',
  ];

You can also customize the validation messages:, (*7)

  public static $messages = [
    // validation messages
    'name' => 'The Name field is required.'
  ];

When you're ready to save a model, you can do it in two ways:, (*8)

The Traditional Way

$item = Item::find($id);
$input = Input::all();

$validation = $item->fill($input)->save() ?: $item->errors;

The Abstraction Way

$item = Item::find($id);
$input = Input::all();

$validation = $item->fillAndSave($input) ?: $item->errors;

Yes, the fillAndSave(array $attributes) method simply executes fill(array $attributes) and returns save()., (*9)

Contributing

This package is a minimal package to streamline the validation process, potentially eliminating the need for Validation and/or Creation services. That being said, contributions to this package will be considered accordingly. Please feel free to submit issues and/or pull-requests if you think there is something that Abstraction could do better., (*10)

The Versions

14/11 2013

dev-master

9999999-dev

Abstraction - Abstract

  Sources   Download

The Requires

 

by Adam Engebretson

laravel abstract