2017 © Pedro PelĂĄez
 

library html

Build form fields, menus, alert messages and other view components quickly

image

styde/html

Build form fields, menus, alert messages and other view components quickly

  • Wednesday, August 1, 2018
  • by sileence
  • Repository
  • 19 Watchers
  • 225 Stars
  • 48,992 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 59 Forks
  • 1 Open issues
  • 34 Versions
  • 8 % Grown

The README.md

StydeNet Html package

Build Status Downloads Version License, (*1)

This package contains a collection of Laravel PHP classes designed to generate common HTML components, such as:, (*2)

  • Menus
  • Alert messages
  • Form fields
  • Collection of radios and checkboxes

This is an extension of the Laravel Collective HTML package and will be very useful if you are working on a custom CMS, an admin panel or basically any project that needs to generate HTML dynamically., (*3)

How to install

  1. The preferred way to install this package is through Composer:

Laravel 6.0 users / Laravel 7.0 users:, (*4)

Install by running composer require "styde/html=~1.8" or adding "styde/html": "~1.8" to your composer.json file and then running composer update., (*5)

Laravel 5.8 users:, (*6)

Install by running composer require "styde/html=~1.7" or adding "styde/html": "~1.7" to your composer.json file and then running composer update., (*7)

Laravel 5.7 users:, (*8)

Install by running composer require "styde/html=~1.6" or adding "styde/html": "~1.6" to your composer.json file and then running composer update., (*9)

Laravel 5.6 users:, (*10)

Install by running composer require "styde/html=~1.5" or adding "styde/html": "~1.5" to your composer.json file and then running composer update., (*11)

Laravel 5.5 users:, (*12)

Install by running composer require "styde/html=~1.4" or adding "styde/html": "~1.4" to your composer.json file and then running composer update., (*13)

  1. Next, add the new provider to the providers array in config/app.php (this step is not necessary if you are using Laravel 5.5 with package auto-discovery)
'providers' => [
    // ...
    Styde\Html\HtmlServiceProvider::class,
    // ...
],
  1. Also, you need to register in the app/Http/Kernel.php file the \Styde\Html\Alert\Middleware::class middleware BEFORE the EncryptCookies middleware, for Laravel 5.8 and later the middleware needs to be registered AFTER the StartSession middleware. For Laravel 5.4 and later, it's in the $middlewareGroups array and for previous versions (Laravel 5.3, 5.2, 5.1) it's in the $middleware array:
// For Laravel 5.4 and later
protected $middlewareGroups = [
    // For Laravel 5.8 and later this needs to be after the StartSession middleware
    \Styde\Html\Alert\Middleware::class,
    //...
];

// For Laravel 5.3, 5.2, 5.1
protected $middleware = [
    //...
    \Styde\Html\Alert\Middleware::class,
    //...
];

This middleware is needed to make the alert messages persistent between sessions, after each request is completed., (*14)

Please notice that the following global aliases will be automatically available (you don't need to add them):, (*15)

Alert => Styde\Html\Facades\Alert
Field => Styde\Html\Facades\Field
Menu  => Styde\Html\Facades\Menu
Form  => Collective\Html\FormFacade
Html  => Collective\Html\HtmlFacade

If you plan to use the Access Handler as a standalone class, you will need to add the following alias:, (*16)

'aliases' => [
    // ...
    'Access' => Styde\Html\Facades\Access::class,
    // ...
],

Optionally, you may also run php artisan vendor:publish --provider='Styde\Html\HtmlServiceProvider' to publish the configuration file in config/html.php and review its options and values., (*17)

Usage

Since this package is largely using LaravelCollective/Html, its documentation for forms and fields is applicable to this package., (*18)

Sandbox

Build Status, (*19)

This package aims to stay well documented and unit tested; however, there is another repository that includes integration tests and several routes, so you can clone it to watch the components of this package in action in your browser or run the included integration tests., (*20)

Check out the sandbox repository, (*21)

You can review those examples and tests as another way to learn more about what you can do with this component, besides reading the documentation., (*22)

Configuration

This package was created with configuration in mind, if you haven't used this component before, you can simply run:, (*23)

php artisan vendor:publish --provider='Styde\Html\HtmlServiceProvider'

this will publish all the configuration options to: config/html.php file, where you can explore and read the comments to learn more about the configuration options and their values., (*24)

Note: Since the default configuration will be merged with the custom configuration, you don't need to publish the entire configuration in every project; instead, just set the values you need to override., (*25)

Read this documentation to learn more about the different configuration options this package provides., (*26)

Form Field builder

The Field Builder will allow you to render the full dynamic markup you need for each form field with only one line of code., (*27)

If you have used the Laravel Collective HTML component before, you already know the basics, simply replace the alias “Form” with “Field”, for example, replace:, (*28)

{!! Form::text('name', 'value', $attributes) !!}

With this:, (*29)

{!! Field::text('name', 'value', $attributes) !!}

Learn more about the field builder, (*30)

Forms

This package adds the following functionality to the Laravel Collective's Form Builder:, (*31)

novalidate

Deactivate the HTML5 validation, ideal for local or development environments, (*32)

//config/html.php
return [
    'novalidate' => true
];

radios

Generate a collection of radios: i.e.:, (*33)

{!! Form::radios('status', ['a' => 'Active', 'i' => 'Inactive']) !!}

checkboxes

Generate a collection of checkboxes, (*34)

$options = [
    'php' => 'PHP',
    'js' => 'JS'
];
$checked = ['php'];
{!! Form::checkboxes('tags', $options, $checked) !!}

Learn more about the form builder, (*35)

Alert messages

This component will allow you to generate complex alert messages., (*36)

Alert::info('Your account is about to expire')
    ->details('Renew now to learn about:')
    ->items(['Laravel', 'PHP', 'And more!'])
    ->button('Renew now!', url('renew'), 'primary');
{!! Alert::render() !!}

Learn more about the alert component, (*37)

Menus are not static elements, sometimes you need to mark the current section, translate items, generate dynamic URLs or show/hide options for certain users., (*38)

So instead of adding a lot of HTML and Blade boilerplate code, you can use this component to generate dynamic menus styled for your preferred CSS framework., (*39)

To generate a menu simply add the following code in your layout’s template:, (*40)

{!! Menu::make('items.here') !!}

Learn more about the menu generator, (*41)

HTML builder

This package extends the functionality of the Laravel Collective’s HTML Builder., (*42)

There’s only one extra method for now, but it’s very useful!, (*43)

Generate CSS classes:

{!! Html::classes(['home' => true, 'main', 'dont-use-this' => false]) !!}

Returns: class="home main", (*44)

Learn more about the HTML builder, (*45)

Helpers

In addition of using the facade methods Alert::message and Menu::make, you can use:, (*46)

alert('this is the message', 'type-of-message')
menu($items, $classes)

Access handler

Sometimes you want to show or hide certain menu items, form fields, etc. for certain users, with this component you can do it without the need of conditionals or too much extra boilerplate code, just pass one of the following options as a field attribute or menu item value., (*47)

  1. callback: a function that should return true if access is granted, false otherwise.
  2. logged: true: requires authenticated user, false: requires guest user.
  3. roles: true if the user belongs to any of the required roles.

i.e.:, (*48)

{!! Field::select('user_id', null, ['roles' => 'admin']) !!}

Learn more about the access handler, (*49)

Themes

There are a lot of CSS frameworks out there, this package was created with that in mind, and even though Bootstrap (version 3 and 4) and Bulma are included out of the box, we plan to add more packages in the future (we also invite you to collaborate)., (*50)

But you can also create your own themes with ease, or modify the existing one:, (*51)

To change and / or customize the theme, simply run:, (*52)

php artisan vendor:publish

Then go to config/html.php and change the theme value:, (*53)

//config/html.php
return [
    'theme' => 'your-theme-here'
];

You can edit and/or create new templates in resources/views/themes/, (*54)

Learn more about the themes, (*55)

Internationalization

This package was also created with internationalization in mind., (*56)

If you don’t plan to use this feature, you can deactivate translations in the configuration, (*57)

//config/html.php
return [
    //

    'translate_texts' => false
    //

];

But if your project needs to implement more than one language or you want to organize all the texts in resources/lang/ instead of hard coding them in the controllers, views, etc. set 'translate_texts' to true., (*58)

Learn more about the internationalization, (*59)

More documentation

You can find a lot of comments if you dig into the source code, as well as unit tests in the spec/ directory, you can also clone the integration tests repository., (*60)

If you have additional questions, feel free to contact me on Twitter (@Sileence) or send me an email to admin@styde.net., (*61)

License

The Styde\Html package is open-sourced software licensed under the MIT license., (*62)

The Versions

01/08 2018

dev-develop

dev-develop

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

01/08 2018

dev-master

9999999-dev

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

05/06 2018

dev-laravel5.5

dev-laravel5.5

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

05/06 2018

1.4.4

1.4.4.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

05/06 2018

1.5.1

1.5.1.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

11/02 2018

1.5.0

1.5.0.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

25/01 2018

1.4.3

1.4.3.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

07/09 2017

1.4.2

1.4.2.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

04/09 2017

1.4.1

1.4.1.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

02/09 2017

1.4.0

1.4.0.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

03/06 2017

dev-laravel5.4

dev-laravel5.4

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

MIT

The Requires

 

The Development Requires

30/01 2017

1.3.0

1.3.0.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

29/01 2017

dev-laravel5.3

dev-laravel5.3

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

21/11 2016

1.2.3

1.2.3.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

21/11 2016

1.2.2

1.2.2.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

27/10 2016

1.2.1

1.2.1.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

27/10 2016

dev-laravel5.1

dev-laravel5.1

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

27/10 2016

1.0.13

1.0.13.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

18/09 2016

1.2.0

1.2.0.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

17/09 2016

1.1.1

1.1.1.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

16/09 2016

1.0.12

1.0.12.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

25/12 2015

1.1.0

1.1.0.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

25/12 2015

1.0.11

1.0.11.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

06/11 2015

1.0.10

1.0.10.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

27/09 2015

1.0.9

1.0.9.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

27/09 2015

1.0.8

1.0.8.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

04/09 2015

1.0.7

1.0.7.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

31/08 2015

1.0.6

1.0.6.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

29/08 2015

1.0.5

1.0.5.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

15/08 2015

1.0.4

1.0.4.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

13/08 2015

1.0.3

1.0.3.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

13/08 2015

1.0.2

1.0.2.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

10/08 2015

1.0.1

1.0.1.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires

22/07 2015

1.0

1.0.0.0

Build form fields, menus, alert messages and other view components quickly

  Sources   Download

The Requires

 

The Development Requires