HTML and Form Builders for the Laravel Framework

Maintainers

Package info

github.com/cyberwolf888/collective-html

Homepage

pkg:composer/cyberwolf888/html

Statistics

Installs: 72

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

8.0.0 2025-05-26 07:51 UTC

This package is auto-updated.

Last update: 2026-02-26 05:58:45 UTC


README

HTML and Form Builders for the Laravel Framework โ€” a maintained fork of LaravelCollective/html.

Latest Stable Version Total Downloads License PHP Laravel

โœจ Features

  • ๐Ÿ—๏ธ Form Builder โ€” open/close forms, model binding, CSRF tokens, and all input types
  • ๐Ÿ”— HTML Builder โ€” generate links, scripts, styles, lists, images, meta tags, and more
  • โšก Macro & Component support โ€” extend both builders with your own methods
  • ๐Ÿ”„ Laravel auto-discovery โ€” no manual provider/alias registration needed
  • ๐Ÿงช Laravel 6โ€“12 compatible with PHP 8.2+

๐Ÿ“ฆ Installation

composer require cyberwolf888/html

Laravel's auto-discovery will register the service provider and facades automatically.

If you prefer manual registration, add to config/app.php:

'providers' => [
    Collective\Html\HtmlServiceProvider::class,
],

'aliases' => [
    'Form' => Collective\Html\FormFacade::class,
    'Html' => Collective\Html\HtmlFacade::class,
],

๐Ÿš€ Usage

Form Builder

{{-- Open a form --}}
{!! Form::open(['url' => '/login', 'method' => 'POST']) !!}

{{-- Model-bound form --}}
{!! Form::model($user, ['route' => ['users.update', $user->id], 'method' => 'PUT']) !!}

{{-- Common inputs --}}
{!! Form::label('email', 'E-Mail Address') !!}
{!! Form::email('email', null, ['class' => 'form-control', 'placeholder' => 'you@example.com']) !!}

{!! Form::label('password', 'Password') !!}
{!! Form::password('password', ['class' => 'form-control']) !!}

{!! Form::label('role', 'Role') !!}
{!! Form::select('role', ['admin' => 'Admin', 'user' => 'User'], 'user') !!}

{!! Form::checkbox('remember', 1, true) !!} Remember me

{!! Form::submit('Login', ['class' => 'btn btn-primary']) !!}

{!! Form::close() !!}

Available Form Methods

Method Description
Form::open() / Form::close() Open and close a form tag
Form::model($model, $options) Model-bound form
Form::token() CSRF hidden input
Form::label($name, $value) Label element
Form::text/email/password/number/... Standard text inputs
Form::textarea($name) Textarea
Form::select($name, $list) Select dropdown
Form::selectRange/selectYear/selectMonth Range/year/month selects
Form::checkbox/radio Checkbox and radio inputs
Form::file($name) File upload input
Form::submit/button/reset Submit, button and reset
Form::hidden($name, $value) Hidden input
Form::date/time/datetime/... Date/time inputs
Form::color/range/search/tel/url/week Specialized HTML5 inputs
Form::datalist($id, $list) Datalist element

HTML Builder

{{-- Scripts and styles --}}
{!! Html::script('js/app.js') !!}
{!! Html::style('css/app.css') !!}

{{-- Links --}}
{!! Html::link('https://example.com', 'Visit Site', ['class' => 'btn']) !!}
{!! Html::linkRoute('home', 'Home') !!}
{!! Html::mailto('hello@example.com', 'Contact Us') !!}

{{-- Images --}}
{!! Html::image('img/logo.png', 'Logo', ['width' => 100]) !!}
{!! Html::favicon('img/favicon.ico') !!}

{{-- Lists --}}
{!! Html::ul(['Apple', 'Banana', 'Cherry']) !!}
{!! Html::ol(['First', 'Second', 'Third']) !!}

{{-- Meta tags --}}
{!! Html::meta('description', 'My awesome page') !!}

{{-- Arbitrary tag --}}
{!! Html::tag('span', 'Hello', ['class' => 'badge']) !!}

Macros

Extend either builder with custom macros:

// AppServiceProvider::boot()
Form::macro('phone', function ($name, $value = null, $options = []) {
    return Form::tel($name, $value, array_merge(['pattern' => '[0-9]{10,15}'], $options));
});

Html::macro('badge', function ($text, $class = 'primary') {
    return new \Illuminate\Support\HtmlString(
        "<span class=\"badge badge-{$class}\">{$text}</span>"
    );
});

๐Ÿค Contributing

Please read CONTRIBUTING.md before submitting pull requests.

๐Ÿ“„ License

This package is open-sourced software licensed under the MIT license.