承接 souravmsh/laravel-html 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

souravmsh/laravel-html

最新稳定版本:v1.0.0

Composer 安装命令:

composer require souravmsh/laravel-html

包简介

HTML and Form Builders for Laravel

README 文档

README

A lightweight HTML and Form Builders library for Laravel.

Motivation & History

For years, the laravelcollective/html package was standard for managing forms and HTML in Laravel applications. However, as Laravel progressed into newer major releases, the laravelcollective/html package was deprecated and stopped receiving support.

This presented a significant upgrade hurdle: legacy codebases with hundreds of forms utilizing the Form:: facade would require massive refactoring efforts just to upgrade the core Laravel framework.

Laravel HTML Form was built to solve this exact problem. It serves as a custom, lightweight, drop-in replacement that precisely mimics the API and core features of the original laravelcollective/html package. By simply installing this library, you can safely upgrade your project to modern Laravel versions without needing to rewrite a single line of your existing Blade templates!

Features

  • Seamless drop-in replacement for legacy syntax
  • Compatible with Laravel 10.x, 11.x, 12.x and 13.x
  • Automatic CSRF Token injection
  • Automatic method spoofing (PUT, PATCH, DELETE)
  • Form Model Binding (including nested dot.notation elements)
  • Supports repopulating with old() session inputs

Installation

composer require souravmsh/laravel-html

Quick Start

This package provides the Form facade which allows you to build HTML forms easily.

Opening a Form

{!! Form::open(['url' => 'foo/bar']) !!}
    //
{!! Form::close() !!}

Using Named Routes:

{!! Form::open(['route' => 'route.name']) !!}

Using Controller Actions:

{!! Form::open(['action' => 'Controller@method']) !!}

Specifying the Method: By default, forms using the open method will use POST. You can customize this:

{!! Form::open(['url' => 'foo/bar', 'method' => 'put']) !!}

Note: Since HTML forms only support POST and GET, PUT, PATCH and DELETE will be spoofed by automatically adding a _method hidden field to your form.

File Uploads: If your form includes file uploads, add a files option:

{!! Form::open(['url' => 'foo/bar', 'files' => true]) !!}

Model Binding

You can populate forms automatically using model binding. It automatically gets values from old() session inputs and falls back to attributes of your model instance. It also supports dot notation formatting for array inputs like address.city.

{!! Form::model($user, ['route' => ['user.update', $user->id], 'method' => 'put']) !!}
    {!! Form::text('name') !!}
{!! Form::close() !!}

Labels & Inputs

Labels

{!! Form::label('email', 'E-Mail Address', ['class' => 'control-label']) !!}

Text, Email & Password

{!! Form::text('username', null, ['class' => 'form-control']) !!}
{!! Form::email('email', null, ['class' => 'form-control']) !!}
{!! Form::password('password', ['class' => 'form-control']) !!}

Note: Password inputs do not prepopulate from old input or model binding.

Other Inputs

{!! Form::number('age', null, ['class' => 'form-control']) !!}
{!! Form::date('birthdate', null, ['class' => 'form-control']) !!}
{!! Form::url('website_url', null, ['class' => 'form-control']) !!}
{!! Form::hidden('invisible', 'secret') !!}

Textarea

{!! Form::textarea('description', null, ['class' => 'form-control', 'rows' => 3]) !!}

File Uploads

{!! Form::file('avatar', ['class' => 'form-control-file']) !!}

Checkboxes and Radio Buttons

{!! Form::checkbox('name', 'value', true) !!} <!-- true sets it as checked -->
{!! Form::radio('name', 'value', true) !!}

Dropdown Lists (Select)

You may pass an array (or a collection) into the select method:

{!! Form::select('size', ['L' => 'Large', 'S' => 'Small'], 'S', ['placeholder' => 'Select a size']) !!}

Grouped Lists:

{!! Form::select('animal', [
    'Cats' => ['leopard' => 'Leopard'],
    'Dogs' => ['spaniel' => 'Spaniel'],
], null) !!}

Buttons

{!! Form::submit('Submit Now', ['class' => 'btn btn-primary']) !!}
{!! Form::button('Click Me', ['class' => 'btn btn-secondary', 'type' => 'button']) !!}

Helper Functions

In addition to the Form facade, this package also provides a form() global helper function. This is especially useful if you prefer function-based syntax over static facade method calls.

{!! form()->open(['url' => 'foo/bar']) !!}
    {!! form()->text('name', null, ['class' => 'form-control']) !!}
{!! form()->close() !!}

Extending / Macros

Since the underlying FormBuilder uses the Macroable trait, you can easily register your own custom methods:

Form::macro('myField', function() {
    return '<input type="awesome">';
});

Then use it via:

{!! Form::myField() !!}

License

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

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固