dartika/laravel-uploadable-mutator

Trait to upload files on setter (when submit file in forms) input
59
Install
composer require dartika/laravel-uploadable-mutator
Latest Version:0.1.1
PHP:>=5.6.4
License:MIT
Last Updated:Oct 16, 2017
Links: GitHub  ·  Packagist
Maintainer: mbellido

Laravel Uploadable Mutator

Trait to upload files from inputs forms through mutator easily.

Installation

Include this in your composer.json:

{
    "require": {
        "dartika/laravel-uploadable-mutator": "dev-master"
    }
}

and then execute:

$ composer update

How to Use

In your model, add the Dartika\UploadableMutator\UploadableMutator trait:

use Dartika\UploadableMutator\UploadableMutator;

class Post extends Model {
    use UploadableMutator;
}

Now, add protected $fileFields array with all file fields ('input' => 'upload path') in your model:

protected $fileFields = [
    'image' => 'public/images',
    'pdf' => 'public/pdfs',
];

That's it!

When you save this fields, it will be uploaded automatically.

Example:

Post::create([
    'title' => 'Hello world'
    'image' => $request->image
]);

Notes

  • If you set a string instead of a file upload, it will be set without upload.
  • If empty input if sends, it will not be replace, it keep the old value.
  • To force empty field, you must create new function to overwritte it with $this->attributes['input'] = "";

Dártika Networks SL

Related Packages

erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

628,058,007 9,707
laravel/framework

The Laravel Framework.

576,155,700 34,907
laravel/tinker

Powerful REPL for the Laravel framework.

485,678,092 7,440