lucasvdh/laravelmacros

A useful set of HTML and Form macros with css and js made for bootstrap

5.3 2017-02-27 16:09 UTC

This package is auto-updated.

Last update: 2024-04-06 22:51:42 UTC


README

A useful set of HTML and Form macros with corresponding CSS and Javascript resources. Made for Bootstrap.

Check out the 4.0 branch for Laravel 4 support.

Getting started

  1. Include the package in your application
  2. Register the service provider
  3. Publish and include the styles and scripts

View the examples.

Include the package in your application

composer require lucasvdh/laravelmacros:5.*

Or add a requirement to your project's composer.json

    "require": {
        "lucasvdh/laravelmacros": "5.*"
    },

Register the service provider

Edit the config/app.php file. Append the following to the providers array:

  'providers' => [
    // ...
    Lucasvdh\LaravelMacros\MacroServiceProvider::class,
    // ...
  ],

If you didn't have the laravelcollective/html package yet, be sure to add that service provider too:

  'providers' => [
    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
  ],

And register the aliases:

 'aliases' => [
    // ...
    'Form' => Collective\Html\FormFacade::class,
    'Html' => Collective\Html\HtmlFacade::class,
    // ...
  ],

Publish and include the styles and scripts

$ php artisan vendor:publish --provider="Lucasvdh\LaravelMacros\MacroServiceProvider"

Publishing a specific resource

$ php artisan vendor:publish --provider="Lucasvdh\LaravelMacros\MacroServiceProvider" --tag="scripts"
$ php artisan vendor:publish --provider="Lucasvdh\LaravelMacros\MacroServiceProvider" --tag="styles"
$ php artisan vendor:publish --provider="Lucasvdh\LaravelMacros\MacroServiceProvider" --tag="images"

The CSS and Javascript files will be published to public/css and public/js.

Make sure to include these in the view where you want to use the macros. You have two choices for including the styles and scripts.

Include all

Either you include all the plugins as a minified file.

<html>
    <head>
        ...
        <link href="/css/laravel-macros.css" rel="stylesheet">
    </head>
    <body>
        ...
        <!-- Include Javascript at the end of body to improve page load speed -->
        <script src="/js/laravel-macros.js" type="text/javascript"></script>
    </body>
</html>

Include specific plugins

Or you include specific plugins.

<html>
    <head>
        ...
        <link href="/css/chosen.css" rel="stylesheet">
        <link href="/css/tags-input.css" rel="stylesheet">
    </head>
    <body>
        ...
        <!-- Include Javascript at the end of body to improve page load speed -->
        <script src="/js/chosen.jquery.min.js" type="text/javascript"></script>
        <script src="/js/tags-input.js" type="text/javascript"></script>
        
        <!-- IMPORTANT this file is required for the plugins to function -->
        <script src="/js/laravel-macros-app.js" type="text/javascript"></script>
    </body>
</html>

That's it

You can now use the macros and all should work. Customization of the CSS and Javascript files should be straight forward.

Below, a few examples are given how to use these macros:

Examples

Date picker

{!! Form::datepicker('field_name', $default, ['class' => 'some-class']) !!}

datepicker

datepicker-extended

Chosen select

{!! Form::chosen('field_name', $default, $list, ['class' => 'some-class']) !!}

chosen

chosen-extended

Material checkbox

{!! Form::materialCheckbox('field_name', $checked, 'This is the checkbox text', 'value', ['class' => 'some-class']) !!}

material-checkbox

material-checkbox-checked

Material radio

{!! Form::materialRadio('field_name', $default, $options = ['value' => 'label'], ['class' => 'some-class']) !!}

material-radio