Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Form Laravel Package

devture/form

Laravel form builder for constructing, validating, and rendering HTML forms using a structured API. Helps define fields, rules, and layout in PHP and output consistent form markup for your views.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require devture/form
    

    No service provider or package discovery needed—just autoload.

  2. First Use Case: Basic Form Binding Define a form class:

    use Devture\Form\Form;
    
    class UserForm extends Form
    {
        public string $name;
        public int $age;
    }
    

    Bind request data:

    $form = new UserForm();
    $form->bind($_POST); // or request()->all() in Laravel
    
  3. Where to Look First

    • Source Code (if available)
    • Form class docs (methods: bind(), validate(), errors())
    • Validation trait (if extended)

Implementation Patterns

Workflow: Request Handling

  1. Instantiate Form
    $form = new UserForm();
    
  2. Bind Input
    $form->bind(request()->all());
    
  3. Validate
    if ($form->validate()) {
        // Process data
        $form->save(); // Custom method
    }
    
  4. Render Errors
    @foreach ($form->errors() as $field => $messages)
        <div>{{ $field }}: {{ implode(', ', $messages) }}</div>
    @endforeach
    

Integration with Laravel

  • Form Requests Extend FormRequest and use the form for validation:
    public function rules()
    {
        $form = new UserForm();
        $form->bind($this->all());
        return $form->rules(); // Hypothetical; check actual API
    }
    
  • Blade Integration Create a helper macro:
    Blade::directive('form', function ($formClass) {
        return "<?php \$form = new {$formClass}(); \$form->bind(request()->all()); ?>";
    });
    
    Usage:
    @form(UserForm)
    <input name="name" value="{{ $form->name }}">
    

Dynamic Rules

Define rules in the form class:

class UserForm extends Form
{
    public string $email;

    protected function rules(): array
    {
        return [
            'email' => 'required|email',
        ];
    }
}

Gotchas and Tips

Pitfalls

  1. No Built-in CSRF Unlike Laravel’s FormRequest, this package doesn’t handle CSRF tokens. Add manually:
    if (!hash_equals($_POST['_token'], csrf_token())) {
        abort(419);
    }
    
  2. Type Safety Binding raw input may cause type mismatches (e.g., "123"int). Cast explicitly:
    $form->age = (int) $form->age;
    
  3. Validation Messages Customize messages via messages() method (if supported):
    protected function messages(): array
    {
        return [
            'email.required' => 'We need your email address!',
        ];
    }
    

Debugging

  • Dump Bound Data
    dd($form->toArray()); // Hypothetical; check actual API
    
  • Validate Without Binding
    $form->validate(['name' => 'John', 'age' => '30']);
    

Extension Points

  1. Custom Validation Extend the Form class to add logic:
    class UserForm extends Form
    {
        public function validateAge()
        {
            if ($this->age < 18) {
                $this->addError('age', 'Must be 18+');
            }
        }
    }
    
  2. Sanitization Override bind() to sanitize input:
    public function bind(array $data): void
    {
        $data = array_map('trim', $data);
        parent::bind($data);
    }
    
  3. Mass Assignment Whitelist fields explicitly:
    protected $fillable = ['name', 'email'];
    

Config Quirks

  • No Config File All behavior is code-driven. Avoid expecting .env or config/form.php.
  • Default Rules If no rules() method exists, the form assumes no validation. Define explicitly.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope