jobmetric / laravel-custom-field
This is a custom field management package for Laravel that you can use in your projects.
Installs: 40
Dependents: 3
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 0
pkg:composer/jobmetric/laravel-custom-field
Requires
- php: >=8.0.1
- jobmetric/laravel-package-core: ^1.31.1
- laravel/framework: >=9.19
README
Laravel Custom Field
This package provides a fluent builder API to define, render, and serialize form fields (text, number, select, radio, image, etc.) with consistent HTML output and an extendable option/data system.
-
Core Concepts
- Builder:
src/CustomFieldBuilder.php - Field Instances:
src/Fields/* - Options (for select/radio):
src/Option/* - Data attributes (data-*) :
src/Attribute/Data/*
- Builder:
-
Usage Highlights
- Chain field attributes and properties (name, label, required, placeholder, ...)
- Add options via closure (bulk) or array
- Render as HTML (
toHtml) or array (toArray) for APIs
Installation
composer require jobmetric/laravel-custom-field
Documentation
This package includes different parts that I will mention in order:
-
Fields
-
Core
Quick Start
use JobMetric\\CustomField\\CustomFieldBuilder; // Text field $text = CustomFieldBuilder::text() ->name('user[name]') ->label('Name') ->info('Enter your full name') ->required() ->placeholder('Enter name') ->build(); // Select with bulk options via a single closure $select = CustomFieldBuilder::select() ->name('country') ->label('Country') ->info('Choose your country') ->options(function ($opt) { $opt->label('Iran')->value('IR')->selected()->build(); $opt->label('Germany')->value('DE')->build(); }) ->build(); // Radio (pro mode) $radio = CustomFieldBuilder::radio() ->name('plan') ->options(function ($opt) { $opt->mode('pro')->type('radio')->name('plan')->label('Basic')->value('basic'); $opt->mode('pro')->type('radio')->name('plan')->label('Enterprise')->value('enterprise')->selected(); }) ->build(); echo $text->toHtml(); echo $select->toHtml(); echo $radio->toHtml();
License
The MIT License (MIT). Please see License File for more information.