webmachine/custom-fields

CustomFields for Laravel 5

dev-master 2022-03-10 18:53 UTC

This package is auto-updated.

Last update: 2024-11-11 00:49:46 UTC


README

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.