PHPackages                             tuijncode/html - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. tuijncode/html

Abandoned → [spatie/laravel-html](/?search=spatie%2Flaravel-html)ArchivedLibrary[Templating &amp; Views](/categories/templating)

tuijncode/html
==============

HTML and Form Builders for the Laravel Framework

v2.0.2(8mo ago)0841MITPHPPHP ^8.2

Since Apr 5Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/tuijncode/html)[ Packagist](https://packagist.org/packages/tuijncode/html)[ Docs](https://github.com/tuijncode/html)[ RSS](/packages/tuijncode-html/feed)WikiDiscussions main Synced yesterday

READMEChangelog (3)DependenciesVersions (4)Used By (0)

Html
====

[](#html)

[![Total Downloads](https://camo.githubusercontent.com/479ea10cd73eb2fe5baebce7b286f1b7ea96c0ad9c3ff80d71094930fb0e571c/68747470733a2f2f706f7365722e707567782e6f72672f7475696a6e636f64652f68746d6c2f642f746f74616c2e737667)](https://packagist.org/packages/tuijncode/html)[![Latest Stable Version](https://camo.githubusercontent.com/1c5264c9d06a6e404b82505dc87bb764aafb71599524b1425bdfdc5f311e6353/68747470733a2f2f706f7365722e707567782e6f72672f7475696a6e636f64652f68746d6c2f762f737461626c652e737667)](https://packagist.org/packages/tuijncode/html)[![License](https://camo.githubusercontent.com/4d649290f817990cbdae58e12b184708c5ee1e2c5a62fd13a39ec6ebfc125558/68747470733a2f2f706f7365722e707567782e6f72672f7475696a6e636f64652f68746d6c2f6c6963656e73652e737667)](https://packagist.org/packages/tuijncode/html)

[![Html](https://camo.githubusercontent.com/fd035172742a2cdf96b1f3bb00e5fd471baf8ade3ad5fed41cca4cca5249492a/68747470733a2f2f63646e2e7475696a6e636f64652e636f6d2f6769746875622f68746d6c2e706e67)](https://camo.githubusercontent.com/fd035172742a2cdf96b1f3bb00e5fd471baf8ade3ad5fed41cca4cca5249492a/68747470733a2f2f63646e2e7475696a6e636f64652e636f6d2f6769746875622f68746d6c2e706e67)

Thank you, **The Laravel Collective**, for creating the original [![package](https://github.com/LaravelCollective/html)](https://github.com/LaravelCollective/html).

LaravelVersion11v2.0.110v1.0Installation
------------

[](#installation)

```
composer require tuijncode/html

```

Important
---------

[](#important)

Since this package internally uses strict comparisons (**===** instead of **==**) be careful when passing numeric values into your forms. Values in HTML are submitted as strings and Laravel old values stored in flash session are strings.

In this example, this package will correctly insert **selected** HTML attribute into the radio input - because the passed value '1' strictly equals to the old submitted value in the session **'1'**:

```
{{ Form::radio('category_id', '1') }} // '1' === '1' - comparing passed value and old session value

```

However, in this example, the passed integer value **1** is not strictly equal to the old submitted string value **'1'** in the session and the **selected** HTML attribute will not be inserted:

Opening A Form
--------------

[](#opening-a-form)

### Opening A Form

[](#opening-a-form-1)

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

```

By default, a **POST** method will be assumed; however, you are free to specify another method:

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

```

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

You may also open forms that point to named routes or controller actions:

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

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

```

You may pass in route parameters as well:

```
{{ Form::open(['route' => ['route.name', $user->id]]) }}

{{ Form::open(['action' => ['Controller@method', $user->id]]) }}

```

If your form is going to accept file uploads, add a **files** option to your array:

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

```

CSRF Protection
===============

[](#csrf-protection)

Adding The CSRF Token To A Form
-------------------------------

[](#adding-the-csrf-token-to-a-form)

Laravel provides an easy method of protecting your application from cross-site request forgeries. First, a random token is placed in your user's session. If you use the **Form::open** method with **POST**, **PUT** or **DELETE** the CSRF token will be added to your forms as a hidden field automatically. Alternatively, if you wish to generate the HTML for the hidden CSRF field, you may use the **token** method:

```
{{ Form::token() }}

```

Attaching The CSRF Filter To A Route
------------------------------------

[](#attaching-the-csrf-filter-to-a-route)

```
Route::post('profile',
    [
    'before' => 'csrf',
        function()
        {
            //
        }
    ]
);

```

Form Model Binding
==================

[](#form-model-binding)

Opening A Model Form
--------------------

[](#opening-a-model-form)

Often, you will want to populate a form based on the contents of a model. To do so, use the **Form::model** method:

```
{{ Form::model($user, ['route' => ['user.update', $user->id]]) }}

```

Now, when you generate a form element, like a text input, the model's value matching the field's name will automatically be set as the field value. So, for example, for a text input named **email**, the user model's **email** attribute would be set as the value. However, there's more! If there is an item in the Session flash data matching the input name, that will take precedence over the model's value. So, the priority looks like this:

1. Session Flash Data (Old Input)
2. Explicitly Passed Value
3. Model Attribute Data

This allows you to quickly build forms that not only bind to model values, but easily re-populate if there is a validation error on the server!

***Note:** When using Form::model, be sure to close your form with **Form::close**!*

Form Model Accessors
--------------------

[](#form-model-accessors)

Laravel's [Eloquent Accessor](https://laravel.com/docs/10.x/eloquent-mutators) allow you to manipulate a model attribute before returning it. This can be extremely useful for defining global date formats, for example. However, the date format used for display might not match the date format used for form elements. You can solve this by creating two separate accessors: a standard accessor, and/or a form accessor.

To define a form accessor, create a **formFooAttribute** method on your model where **Foo** is the "camel" cased name of the column you wish to access. In this example, we'll define an accessor for the **date\_of\_birth** attribute. The accessor will automatically be called by the HTML Form Builder when attempting to pre-fill a form field when **Form::model()** is used.

You must include the FormAccessible trait in your model definition for this to work.

```
