PHP code example of fajarsulaksono / laravel-collective-html
1. Go to this page and download the library: Download fajarsulaksono/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/ */
fajarsulaksono / laravel-collective-html example snippets
'providers' => [
Collective\Html\HtmlServiceProvider::class,
],
'aliases' => [
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
],
use Collective\Html\HtmlFacade as Html;
// Links
{!! Html::link('/about', 'About Us') !!}
{!! Html::linkRoute('users.index', 'Users') !!}
{!! Html::linkAsset('css/app.css', 'Stylesheet') !!}
{!! Html::mailto('[email protected] ') !!}
// Images
{!! Html::image('logo.png', 'Logo', ['class' => 'logo']) !!}
// Lists
{!! Html::ul(['Item 1', 'Item 2'], ['class' => 'list']) !!}
{!! Html::ol(['First', 'Second']) !!}
{!! Html::dl(['Term' => 'Definition']) !!}
// Meta / Script / Style
{!! Html::meta('csrf-token', csrf_token()) !!}
{!! Html::script('js/app.js') !!}
{!! Html::style('css/app.css') !!}
{!! Html::favicon('favicon.ico') !!}
// Arbitrary tag
{!! Html::tag('div', 'Content', ['class' => 'wrapper']) !!}
use Collective\Html\FormFacade as Form;
// Open a form (auto-generates CSRF token and method spoofing)
{!! Form::open(['route' => 'posts.store']) !!}
{!! Form::close() !!}
// With model binding
{!! Form::model($post, ['route' => ['posts.update', $post->id], 'method' => 'PUT']) !!}
{!! Form::close() !!}
// Text inputs
{!! Form::text('name', 'default value', ['class' => 'form-control']) !!}
{!! Form::password('password') !!}
{!! Form::hidden('id', $post->id) !!}
{!! Form::email('email') !!}
{!! Form::number('age') !!}
// Textarea
{!! Form::textarea('body', null, ['rows' => 10, 'cols' => 50]) !!}
// Select
{!! Form::select('size', ['S' => 'Small', 'M' => 'Medium', 'L' => 'Large'], 'M') !!}
// Select with optgroups
{!! Form::select('city', [
'Europe' => ['Paris' => 'Paris', 'Berlin' => 'Berlin'],
'Asia' => ['Tokyo' => 'Tokyo', 'Seoul' => 'Seoul'],
]) !!}
// Select year / month / range
{!! Form::selectYear('year', 2020, 2030) !!}
{!! Form::selectMonth('month') !!}
{!! Form::selectRange('rating', 1, 5) !!}
// Checkboxes & Radios
{!! Form::checkbox('terms', 1) !!}
{!! Form::radio('color', 'red') !!}
// File upload
{!! Form::file('avatar') !!}
// Buttons
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
{!! Form::button('Cancel', ['type' => 'button']) !!}
{!! Form::reset('Reset') !!}
{!! Form::model($user, ['route' => ['users.update', $user->id], 'method' => 'PUT']) !!}
{!! Form::label('name', 'Name') !!}
{!! Form::text('name') !!} {{-- Prefilled from old input or $user->name --}}
{!! Form::label('email', 'Email') !!}
{!! Form::email('email') !!} {{-- Prefilled from old input or $user->email --}}
{!! Form::close() !!}
use Collective\Html\Eloquent\FormAccessible;
class User extends Model
{
use FormAccessible;
public function formNameAttribute($value)
{
return strtoupper($value);
}
}
// Registration (in a service provider or controller boot method)
Form::component('bsText', 'components.form.text', ['name', 'value', 'attributes']);
// Usage in Blade
{!! Form::bsText('email', null, ['class' => 'form-control']) !!}
link_to('/about', 'About Us');
link_to_asset('css/app.css');
link_to_route('users.index', 'Users');
link_to_action('UserController@index', 'Users');