Download the PHP package axn/laravelcollective-form-to-raw-html without Composer
On this page you can find all versions of the php package axn/laravelcollective-form-to-raw-html. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download axn/laravelcollective-form-to-raw-html
More information about axn/laravelcollective-form-to-raw-html
Files in axn/laravelcollective-form-to-raw-html
Package laravelcollective-form-to-raw-html
Short Description Provides Artisan command to replace LaravelCollective Form:: syntax by raw HTML
License MIT
Homepage https://github.com/AXN-Informatique/laravelcollective-form-to-raw-html
Informations about the package laravelcollective-form-to-raw-html
LaravelCollective Form To Raw Html
Provides Artisan command to replace LaravelCollective Form::
syntax by raw HTML
It searches for {!! Form::<method>(<arguments>) !!}
or {{ Form::<method>(<arguments>) }}
,
then analyzes arguments to determine the HTML tag attributes.
- Installation
- Usage
Installation
With Composer, as dev dependency:
Usage
Simply run this command:
By default, the command scans all files in resources/views/
.
You can precise an other directory:
Or a single file:
NOTE: The target path is always relative to the project root.
The supported methods are:
- open(options)
- close()
- label(name, value, options, escape)
- labelRequired(name, value, options, escape)
- input(type, name, value, options)
- text(name, value, options)
- number(name, value, options)
- date(name, value, options)
- time(name, value, options)
- datetime(name, value, options)
- week(name, value, options)
- month(name, value, options)
- range(name, value, options)
- search(name, value, options)
- email(name, value, options)
- tel(name, value, options)
- url(name, value, options)
- color(name, value, options)
- hidden(name, value, options)
- checkbox(name, value, checked, options)
- radio(name, value, checked, options)
- file(name, options)
- password(name, options)
- textarea(name, value, options)
- select(name, list, selected, options)
- button(name, options)
- submit(name, options)
If a method is not supported, there is no replacement.
Warnings and limitations
Escaped echo without double-encode
LaravelCollective internally use most of the time escaped echo without double-encode:
This prevents the encoded HTML entities from being encoded a second time (&
=> &amp;
)
So, you will see the use of this function in the replacement to keep the original behavior.
For example:
The HTML result will be:
Escaped with double-encode
If you do not want to use this feature you can pass the --escape-with-double-encode
option to the command.
So instead of escaping this way:
The values will be escaped like this:
Automatically retrieve field value
LaravelCollective has a complex method to automatically retrieve the value of the field: it searches in "old" values
and in the request. You can see it in the getValueAttribute
method of the FormBuilder
class.
This was to complex to implement entirely, so the converter only handles the value retrieving from the "old" values.
For example:
Will be replaced by:
If you have fields with name as array, the converter will replace the array syntax by dot syntax for the old
helper
like LaravelCollective do.
For example:
Will be replaced by:
If you already used old
helper in the Form::
syntax, the converter will detect it and not doubling the use of the
"old" helper.
WARNING 1: If a part of the name is in a variable (for example Form::text('name['.$index.']')
), the converter will
integrate the replacement function into the output result like this:
WARNING 2: If you have fields with name as array but with no explicit key (for example name[]
), the converter cannot
determine what index to use to get the proper value and will simply render old('name')
instead of old('name.<index>')
.
You may need to check these cases to manually set the proper way to retrieve the value (for example: old('name.0')
).
Automatically determine radio and checkbox checked state
Like for value retrieving, the converter only handles the checked state retrieving from the "old" values. It uses in_array
in case where the "old" value is multiple.
For example:
Will be replaced by:
If a default checked state is specify, for example:
It will appear like this:
Select with optgroup
The Form::select
method accepts grouped arrays of options to render <optgroup>
.
This feature was to complex to implement: this would have required to add to much code in the HTML replacement whose
will be not needed 99% of the time (unless you heavy used optgroups). The converter cannot detect if the list
argument
contains groups so it is not possible to detect cases where optgroups are used. You may need to manually review these cases.
However, the converter can detect if optionsAttributes
or optgroupsAttributes
arguments of Form::builder
have been
used. If so, the corresponding Form::select
will not be replaced.
Comments
If there are comments in the original syntax, the converter will erase these but the original syntax will be preserve
in a comment for manual check. You can retrieve these cases by searching for @TODO CHECK COMMENTS
.
For example:
Will be replaced by:
Not regular array syntax for options
If the options argument is not a regular array, the converter will process the replacement of the Form::
syntax
but will preserve the options in a comment for manual check and manual replacements of the HTML tag attributes.
You can retrieve these cases by searching for @TODO CHECK OPTIONS
.
For example:
Will be replaced by:
Date fields
LaravelCollective date
, time
, datetime
, week
and month
methods support a DateTime
instance as value and format
this internally. The converter cannot detect the value type so you may need to review these cases if DateTime
instances
have been used as value argument of these methods.