PHP code example of prabowosd / laravel-collective-html

1. Go to this page and download the library: Download prabowosd/laravel-collective-html library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

prabowosd / laravel-collective-html example snippets


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

{!! Form::label('email', 'E-Mail Address') !!}

{!! Form::text('username') !!}
{!! Form::textarea('description') !!}
{!! Form::password('password') !!}
{!! Form::hidden('invisible', 'secret') !!}

{!! Form::checkbox('name', 'value') !!}
{!! Form::radio('name', 'value') !!}

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

{!! Form::submit('Click Me!') !!}

{{-- Render the feedback element only when the field has an error --}}
{!! Form::error('email') !!}            // <div class="invalid-feedback">The email field is ptions when the field errors --}}
{!! Form::text('email', null, Form::withValidationClass('email', ['class' => 'form-control'])) !!}

{{-- PHP enum: backed enums use their value; a label() method is honored, --}}
{{-- otherwise the case name is humanized.                                 --}}
{!! Form::enumSelect('status', App\Enums\OrderStatus::class, $selected) !!}

{{-- Eloquent: pass a model class, query/relation, collection, or array --}}
{!! Form::modelSelect('category_id', App\Models\Category::class, 'name', 'id', $selected) !!}
{!! Form::modelSelect('category_id', $categories /* a Collection */, 'title', 'uuid') !!}

enum OrderStatus: string
{
    case Pending = 'pending';
    case Shipped = 'shipped';

    public function label(): string
    {
        return ucfirst($this->value);
    }
}

// config/html.php
return [
    'classes' => [
        'control' => 'form-control',
        'select' => 'form-select',
        'label' => 'form-label',
        'invalid' => 'is-invalid',
        'feedback' => 'invalid-feedback',
        'check_wrapper' => 'form-check',
        'check_input' => 'form-check-input',
        'check_label' => 'form-check-label',
    ],
];
bash
php artisan vendor:publish --tag=html-config