webmachineltda / custom-fields by webmachine

CustomFields for Laravel 5
335
0
3
Package Data
Maintainer Username: webmachine
Maintainer Contact: contacto@webmachine.cl (WebMachine)
Package Create Date: 2017-03-16
Package Last Update: 2022-03-10
Language: PHP
License: MIT
Last Refreshed: 2024-12-22 03:13:04
Package Statistics
Total Downloads: 335
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 3
Total Forks: 0
Total Open Issues: 0

CustomFields for Laravel 5

Install

Via Composer

$ composer require webmachine/custom-fields

Next, you must install the service provider and facade alias:

// config/app.php
'providers' => [
    ...
    Webmachine\CustomFields\CustomFieldsServiceProvider::class,
];

...

'aliases' => [
    ...
    'CustomFields' => Webmachine\CustomFields\CustomFieldsFacade::class,
];

Publish

$ php artisan vendor:publish --provider="Webmachine\CustomFields\CustomFieldsServiceProvider"

Usage

In your Controller, save your custom fields for a given table record:

...
use Webmachine\CustomFields\CustomFieldsFacade as CustomFields;

class FooController extends Controller {
    ...
    public function storage() {
        ...
        $foo->save();
        CustomFields::save($foo->id);
    }
}

In your Request, validate your cutom field

...
use Webmachine\CustomFields\CustomFieldsFacade as CustomFields;

class FooRequest extends Request {
    ...
    public function rules() {
        $rules = [
            ...
        ];       
        $custom_rules = CustomFields::rules('table', 'form_scope');      
        return array_merge($rules, $custom_rules);
    }
    ...
    public function attributes() {
        $attributes = [];
        $custom_attributes = CustomFields::attributes('table', 'form_scope');
        return array_merge($attributes, $custom_attributes);
    }
}

In your view

{!! CustomFields::show('table', 'form_scope') !!}

License

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