• Stars
    star
    266
  • Rank 153,666 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 9 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Laravel package designed to generate common HTML components

StydeNet Html package

Build Status Downloads Version License

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

  • 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.

How to install

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

Laravel 6.0 users / Laravel 7.0 users:

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.

Laravel 5.8 users:

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.

Laravel 5.7 users:

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.

Laravel 5.6 users:

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.

Laravel 5.5 users:

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.

  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.

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

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:

'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.

Usage

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

Sandbox

Build Status

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.

Check out the sandbox repository

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.

Configuration

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

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.

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.

Read this documentation to learn more about the different configuration options this package provides.

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.

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:

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

With this:

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

Learn more about the field builder

Forms

This package adds the following functionality to the Laravel Collective's Form Builder:

novalidate

Deactivate the HTML5 validation, ideal for local or development environments

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

radios

Generate a collection of radios: i.e.:

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

checkboxes

Generate a collection of checkboxes

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

Learn more about the form builder

Alert messages

This component will allow you to generate complex alert messages.

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

Menu generator

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.

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.

To generate a menu simply add the following code in your layout’s template:

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

Learn more about the menu generator

HTML builder

This package extends the functionality of the Laravel Collective’s HTML Builder.

There’s only one extra method for now, but it’s very useful!

Generate CSS classes:

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

Returns: class="home main"

Learn more about the HTML builder

Helpers

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

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.

  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.:

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

Learn more about the access handler

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).

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

To change and / or customize the theme, simply run:

php artisan vendor:publish

Then go to config/html.php and change the theme value:

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

You can edit and/or create new templates in resources/views/themes/

Learn more about the themes

Internationalization

This package was also created with internationalization in mind.

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

//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.

Learn more about the internationalization

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.

If you have additional questions, feel free to contact me on Twitter (@Sileence) or send me an email to [email protected].

License

The Styde\Html package is open-sourced software licensed under the MIT license.

More Repositories

1

enlighten

Enlighten your APIs with auto-generated documentation
PHP
575
star
2

curso-de-laravel-desde-cero

Ejemplos del Curso de Laravel 5.5 desde cero: https://styde.net/laravel-5/
PHP
74
star
3

blade-pagination

Laravel's pagination with Blade templating support
PHP
71
star
4

php-oop

Repositorio para el curso de programación orientada a objetos con PHP.
PHP
33
star
5

teachme

Proyecto del curso "crea tu primera aplicación con Laravel"
PHP
28
star
6

vue2

Código de las lecciones del curso de Vue.js 2
Vue
20
star
7

curso-vuejs

Código de las lecciones de nuestro primer curso sobre VueJS en https://styde.net
JavaScript
18
star
8

foro

JavaScript
16
star
9

laravel5-1

Building a base project for Laravel 5.1
PHP
16
star
10

factory

Generate and build model factories for Laravel using classes and methods instead of closures
PHP
16
star
11

first-steps

PHP
10
star
12

laravel5p2

Repositorio del curso de Laravel 5.2
PHP
8
star
13

seeder

Improved seeders for Laravel 5.0 and 5.1
PHP
8
star
14

notifications_demo

Creación de un módulo de notificación, parte del curso de Laravel 5.3: https://styde.net/curso-de-novedades-en-laravel-5-3/
PHP
8
star
15

form

Advanced form generation for Laravel
PHP
7
star
16

blade-pagination-tests

Integration tests for the Blade Pagination package
PHP
7
star
17

laravel-query-filter

Apply filters to your queries using eloquent.
PHP
7
star
18

unit-tests

Repositorio de la parte 1 del curso: Crea componentes con PHP y Laravel
PHP
6
star
19

design-patterns-php

Repositorio del Curso de Patrones de Diseño en Styde.net
HTML
5
star
20

laravel-test-helpers

A collection of additional helpers to test Laravel applications
PHP
5
star
21

curso-de-laravel-9

Repositorio del curso de Laravel 9
PHP
4
star
22

authentication-methods

Repositorio para el curso Métodos de Autenticación con Laravel
PHP
4
star
23

advanced-eloquent

Curso de Eloquent Avanzado
PHP
3
star
24

gates

Repositorio de la tercera parte del curso de técnicas de autorización: https://styde.net/tecnicas-de-autorizacion-con-laravel/
PHP
3
star
25

primeros-pasos-con-laravel-6

PHP
2
star
26

laravel-dropbox-example

PHP
2
star
27

fast-eloquent

PHP
2
star
28

authorization-techniques

PHP
2
star
29

cars

PHP
2
star
30

vue2-testing

Repositorio del Curso de Testing con Vue.js 2
JavaScript
2
star
31

laravel-7

PHP
2
star
32

eloquent-orm

Curso básico de Eloquent ORM
PHP
2
star
33

container

This is a demo container for the Laravel course (in Spanish) "Creación de Componentes para PHP".
PHP
2
star
34

authorization-demo

Proyecto demo para aprender el nuevo feature de autorización de Laravel como parte del curso introductorio de Laravel 5.1: https://styde.net/curso-introductorio-laravel-5-1/
PHP
2
star
35

html-integration-tests

Sandbox and integration tests for the html package
PHP
1
star
36

mysql-fulltext-search-in-laravel

Repositorio de la serie de FullText Search con MysQL en Laravel
PHP
1
star
37

curso-de-sass

Repositorio para el curso de Sass a fondo en Styde.net
HTML
1
star
38

laravel-training

PHP
1
star
39

laravel-scout-demo

Código fuente de la parte 5 del curso https://styde.net/curso-de-novedades-en-laravel-5-3/
PHP
1
star
40

laravel-and-vue

PHP
1
star
41

refactoring-example

PHP
1
star
42

whetstone

Tool to unit test your Blade views and components
PHP
1
star