2017 © Pedro Peláez
 

library infire

An extension for eloquent class (Laravel)

image

luizgabriel/infire

An extension for eloquent class (Laravel)

  • Thursday, March 12, 2015
  • by luizgabriel
  • Repository
  • 2 Watchers
  • 0 Stars
  • 465 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Infire

An extension for the Eloquent class (Laravel), (*1)

Contents

  • [Installation] (#instalation)
  • [Getting Started] (#getting-started)
  • [Validation with Infire] (#validation-with-infire)
  • [Auto Input Model Filling] (#auto-input-model-filling)
  • [Activing or Deactiving Infire Properties] (#activing-or-deactiving-infire-properties)
  • [File Uploading] (#file-uploading)
  • [Using the Uploader Directly] (#using-the-uploader-directly)

Installation

Add luizgabriel/infire as a requirement to composer.json:, (*2)

  "require" : {
        "luizgabriel/infire": "1.0.*@dev"
  }

Update your packages with composer update or install with composer install., (*3)

Getting Started

To create a new Infire model, simply make your model class derive from the Infire base class. In the next examples we will use the complete namespaced class to make examples cleaner, but you're encouraged to make use of use in all your classes:, (*4)

use Luizgabriel\Infire\Infire;

class MyModel extends Infire
{
   // variables and methods
}

Note: you can also add an alias to your laravel configurations by adding 'Infire' => 'Luizgabriel\Infire\Infire', (*5)

Validation with Infire

Infire models use Laravel's built-in Validator class. Defining validation rules for a model is simple and is typically done in your model class as a static variable:, (*6)

class User extends Infire
{
    public static $rules = [
        'name'                  => 'required|between:4,16',
        'email'                 => 'required|email',
        'password'              => 'required|alpha_num|between:4,8|confirmed',
        'password_confirmation' => 'required|alpha_num|between:4,8',
    ];
}

Infire models validate themselves automatically when Infire->save() is called., (*7)

$user           = new User;
$user->name     = 'John doe';
$user->email    = 'john@doe.com';
$user->password = 'test';

$success = $user->save(); // returns false if model is invalid

Auto Input Model Filling

With infire you can auto fill your model attributes from a form input. For example, let's write a single controller method code., (*8)

class MyController extends BaseController
{
    public function store()
    {
        $user = new User;

        if(!$user->save())
          return Redirect::back()->withErrors($user->errors());

        Redirect::route('users.index');
    }
}

It will have the same effect as, (*9)

class MyController extends BaseController
{
    public function store()
    {
        $user           = new User;
        $user->name     = Input::get('name');
        $user->email    = Input::get('email');
        $user->password =  Hash::make(Input::get('password'));
        //Other fields...

        if(!$user->save())
          return Redirect::back()->withErrors($user->errors());

        Redirect::route('users.index');
    }
}

Activing or Deactiving Infire Properties

You can deactivate the Auto Fill Model by having a public $autoFillAttributes = false;. Infire auto hash your password fields too, you can deactivate this option by having public $autoHashPassword = false;., (*10)

File Uploading

Infire can handle all upload stuff by only having a single array of files like, (*11)

class User extends Infire
{
    protected $fillable = [
        'thumb',
        'profile_image',
        'name',
        'email',
        'password',
    ];

    public $files = ['thumb', 'profile_image'];
    /*
     * When $user->save() is called.
     * Your file input is catch and sent to your Cloudinary storage acount.
     */
}

Using the Uploader Directly

When you have some special kind of upload which is not suported by the default post-upload, you can use the $model->uploader(). This gives you the current uploader to use (based on your configurations). For example:, (*12)

use Symfony\Component\HttpFoundation\File\UploadedFile as File;

class Photo extends Infire
{
    protected $fillable = [
        'image_file',
        'user_id'
    ];

    public $files = ['image_file'];

    public function setImageFileAttribute(File $value)
    {
        $upload = $this->uploader()->upload($file); //Sends the file to the storage server and returns informations about it
        $this->attributes['image_file'] = $this->uploader()->uploadToJson($upload); //Grabs only the important informations
    }

    public function getImageFileAttribute($value, $options = array())
    {
        /*
         * Here you can check if there is no image and return a default one.
         * It's up to your imagination.
         */
        return $this->uploader()->toUrl($value, $options);
    }

}

For the Cloudinary Uploader, the $options array can be used to set informations like width, height, crop and others. (Check more at the [Cloudinary Documentation] (http://cloudinary.com/documentation/image_transformations)), (*13)

The Versions

12/03 2015

1.0.x-dev

1.0.9999999.9999999-dev

An extension for eloquent class (Laravel)

  Sources   Download

MIT

The Requires

 

by Avatar luizgabriel

laravel

26/02 2015

dev-master

9999999-dev

An extension for eloquent class (Laravel)

  Sources   Download

MIT

The Requires

 

by Avatar luizgabriel

laravel