PHPackages                             laravelbook/laravel4-powerpack - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. laravelbook/laravel4-powerpack

ActiveLibrary[Framework](/categories/framework)

laravelbook/laravel4-powerpack
==============================

Port of Laravel 3's HTML, Form and Str classes

v0.2(13y ago)833.8k14[3 issues](https://github.com/laravelbook/laravel4-powerpack/issues)[2 PRs](https://github.com/laravelbook/laravel4-powerpack/pulls)BSD-3-ClausePHPPHP &gt;=5.3.0

Since Jan 22Pushed 13y ago5 watchersCompare

[ Source](https://github.com/laravelbook/laravel4-powerpack)[ Packagist](https://packagist.org/packages/laravelbook/laravel4-powerpack)[ Docs](http://laravelbook.com/)[ RSS](/packages/laravelbook-laravel4-powerpack/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

laravel4-powerpack
==================

[](#laravel4-powerpack)

Brings back the helper classes and methods from Laravel 3 to Laravel 4... and all that in a single, convenient package!

[![Kint debugger](https://camo.githubusercontent.com/000766d173fa37125d60eeab8d2ab5b520fe69d9a9f16dc21d0ec9621ce3ea3b/687474703a2f2f692e696d6775722e636f6d2f356f4f323674612e706e67)](https://camo.githubusercontent.com/000766d173fa37125d60eeab8d2ab5b520fe69d9a9f16dc21d0ec9621ce3ea3b/687474703a2f2f692e696d6775722e636f6d2f356f4f323674612e706e67)

**`laravel4-powerpack`** contains Laravel 4 ports of the following helper classes:

- [HTML](#html_class)
- [Form](#form_class)
- [Str](#str_class)

Installation
============

[](#installation)

Open up the Laravel 4 `composer.json` file and add the `laravelbook/laravel4-powerpack` package to the `require` section:

```
{
	"require": {
		"laravel/framework": "4.0.*",
		...
		"laravelbook/laravel4-powerpack": "dev-master"
	}
	...
}
```

Run the composer `install` or `update` task, which will make composer download requested packages and setup initial environment:

```
$ composer update
```

You'll now have a `composer.json`, `composer.lock` as well as a `vendor` folder which contains:

```
vendor/autoload.php
vendor/composer
vendor/laravel
vendor/laravelbook/laravel4-powerpack
...

```

The folder `vendor/laravelbook/laravel4-powerpack` contain the **Laravel 4 PowerPack** components:

```
vendor/laravelbook/laravel4-powerpack/src/LaravelBook/Laravel4Powerpack/HTML.php
vendor/laravelbook/laravel4-powerpack/src/LaravelBook/Laravel4Powerpack/Form.php
vendor/laravelbook/laravel4-powerpack/src/LaravelBook/Laravel4Powerpack/Str.php

```

By default, composer will autoload the required classes. If you encounter any error, run the following command to force composer re-generate the autoload file:

```
$ composer dump-autoload
```

Next, we need to install the package in your Laravel 4 application. Open up the the `app/config/app.php` file and append the following code to the `providers` array:

```
"LaravelBook\Laravel4Powerpack\Providers\PowerpackServiceProvider",
```

The `providers` section should look like the following snippet:

```
'providers' => array(
    ...
    'LaravelBook\Laravel4Powerpack\Providers\PowerpackServiceProvider',
),
```

Next, add the following code to the `aliases` array in the `app/config/app.php` file:

```
'HTML' => 'LaravelBook\Laravel4Powerpack\Facades\HTMLFacade',
'Form' => 'LaravelBook\Laravel4Powerpack\Facades\FormFacade',
'Str' => 'LaravelBook\Laravel4Powerpack\Facades\StrFacade',
```

The `aliases` array should now look like the snippet below:

```
'aliases' => array(
    ...
	'HTML' => 'LaravelBook\Laravel4Powerpack\Facades\HTMLFacade',
	'Form' => 'LaravelBook\Laravel4Powerpack\Facades\FormFacade',
	'Str' => 'LaravelBook\Laravel4Powerpack\Facades\StrFacade',
),
```

Laravel 4 Powerpack is now ready to be used in your web application!

You can verify the installation by running some simple test code like this:

```
Route::get('/', function() {
	echo Form::open( '/' );
	echo HTML::image( 'img/hello.jpg' );
	echo Form::text( Str::upper('hello world!') );
	echo Form::close();
	echo dd( $_REQUEST );
});
```

Building HTML
=============

[](#building-html)

Content
-------

[](#content)

- [Entities](#entities)
- [Scripts And Style Sheets](#scripts-and-style-sheets)
- [Links](#links)
- [Links To Named Routes](#links-to-named-routes)
- [Links To Controller Actions](#links-to-controller-actions)
- [Mail-To Links](#mail-to-links)
- [Images](#images)
- [Lists](#lists)
- [Custom Macros](#custom-macros)

Entities
--------

[](#entities)

When displaying user input in your Views, it is important to convert all characters which have significance in HTML to their "entity" representation.

For example, the &lt; symbol should be converted to its entity representation. Converting HTML characters to their entity representation helps protect your application from cross-site scripting:

#### Converting a string to its entity representation:

[](#converting-a-string-to-its-entity-representation)

```
echo HTML::entities('alert(\'hi\');');
```

Scripts And Style Sheets
------------------------

[](#scripts-and-style-sheets)

#### Generating a reference to a JavaScript file:

[](#generating-a-reference-to-a-javascript-file)

```
echo HTML::script('js/scrollTo.js');
```

#### Generating a reference to a CSS file:

[](#generating-a-reference-to-a-css-file)

```
echo HTML::style('css/common.css');
```

#### Generating a reference to a CSS file using a given media type:

[](#generating-a-reference-to-a-css-file-using-a-given-media-type)

```
echo HTML::style('css/common.css', array('media' => 'print'));
```

*Further Reading:*

- *[Managing Assets](/docs/views/assets)*

Links
-----

[](#links)

#### Generating a link from a URI:

[](#generating-a-link-from-a-uri)

```
echo HTML::link('user/profile', 'User Profile');
```

#### Generating a link that should use HTTPS:

[](#generating-a-link-that-should-use-https)

```
echo HTML::secure('user/profile', 'User Profile');
```

#### Generating a link and specifying extra HTML attributes:

[](#generating-a-link-and-specifying-extra-html-attributes)

```
echo HTML::link('user/profile', 'User Profile', array('id' => 'profile_link'));
```

Links To Named Routes
---------------------

[](#links-to-named-routes)

#### Generating a link to a named route:

[](#generating-a-link-to-a-named-route)

```
echo HTML::route('profile');
```

#### Generating a link to a named route with wildcard values:

[](#generating-a-link-to-a-named-route-with-wildcard-values)

```
$url = HTML::route('profile', 'User Profile', array($username));
```

*Further Reading:*

- *[Named Routes](/docs/routing#named-routes)*

Links To Controller Actions
---------------------------

[](#links-to-controller-actions)

#### Generating a link to a controller action:

[](#generating-a-link-to-a-controller-action)

```
echo HTML::action('home@index');
```

### Generating a link to a controller action with wildcard values:

[](#generating-a-link-to-a-controller-action-with-wildcard-values)

```
echo HTML::action('user@profile', 'User Profile', array($username));
```

Mail-To Links
-------------

[](#mail-to-links)

The "mailto" method on the HTML class obfuscates the given e-mail address so it is not sniffed by bots.

#### Creating a mail-to link:

[](#creating-a-mail-to-link)

```
echo HTML::mailto('example@gmail.com', 'E-Mail Me!');
```

#### Creating a mail-to link using the e-mail address as the link text:

[](#creating-a-mail-to-link-using-the-e-mail-address-as-the-link-text)

```
echo HTML::mailto('example@gmail.com');
```

Images
------

[](#images)

#### Generating an HTML image tag:

[](#generating-an-html-image-tag)

```
echo HTML::image('img/smile.jpg', $alt_text);
```

#### Generating an HTML image tag with extra HTML attributes:

[](#generating-an-html-image-tag-with-extra-html-attributes)

```
echo HTML::image('img/smile.jpg', $alt_text, array('id' => 'smile'));
```

Lists
-----

[](#lists)

#### Creating lists from an array of items:

[](#creating-lists-from-an-array-of-items)

```
echo HTML::ol(array('Get Peanut Butter', 'Get Chocolate', 'Feast'));

echo HTML::ul(array('Ubuntu', 'Snow Leopard', 'Windows'));

echo HTML::dl(array('Ubuntu' => 'Canonical', 'Windows' => 'Microsoft'));
```

Custom Macros
-------------

[](#custom-macros)

It's easy to define your own custom HTML class helpers called "macros". Here's how it works. First, simply register the macro with a given name and a Closure:

#### Registering a HTML macro:

[](#registering-a-html-macro)

```
HTML::macro('myElement', function()
{
	return '';
});
```

Now you can call your macro using its name:

#### Calling a custom HTML macro:

[](#calling-a-custom-html-macro)

```
echo HTML::myElement();
```

---

Building Forms
==============

[](#building-forms)

Contents
--------

[](#contents)

- [Opening A Form](#opening-a-form)
- [CSRF Protection](#csrf-protection)
- [Labels](#labels)
- [Text, Text Area, Password &amp; Hidden Fields](#text)
- [File Input](#file)
- [Checkboxes and Radio Buttons](#checkboxes-and-radio-buttons)
- [Drop-Down Lists](#drop-down-lists)
- [Buttons](#buttons)
- [Custom Macros](#custom-macros)

> **Note:** All input data displayed in form elements is filtered through the HTML::entities method.

Opening A Form
--------------

[](#opening-a-form)

#### Opening a form to POST to the current URL:

[](#opening-a-form-to-post-to-the-current-url)

```
echo Form::open();
```

#### Opening a form using a given URI and request method:

[](#opening-a-form-using-a-given-uri-and-request-method)

```
echo Form::open('user/profile', 'PUT');
```

#### Opening a Form that POSTS to a HTTPS URL:

[](#opening-a-form-that-posts-to-a-https-url)

```
echo Form::openSecure('user/profile');
```

#### Specifying extra HTML attributes on a form open tag:

[](#specifying-extra-html-attributes-on-a-form-open-tag)

```
echo Form::open('user/profile', 'POST', array('class' => 'awesome'));
```

#### Opening a form that accepts file uploads:

[](#opening-a-form-that-accepts-file-uploads)

```
echo Form::openForFiles('users/profile');
```

#### Opening a form that accepts file uploads and uses HTTPS:

[](#opening-a-form-that-accepts-file-uploads-and-uses-https)

```
echo Form::openSecureForFiles('users/profile');
```

#### Closing a form:

[](#closing-a-form)

```
echo Form::close();
```

CSRF Protection
---------------

[](#csrf-protection)

Laravel provides an easy method of protecting your application from cross-site request forgeries. First, a random token is placed in your user's session. Don't sweat it, this is done automatically. Next, use the token method to generate a hidden form input field containing the random token on your form:

#### Generating a hidden field containing the session's CSRF token:

[](#generating-a-hidden-field-containing-the-sessions-csrf-token)

```
echo Form::token();
```

#### Attaching the CSRF filter to a route:

[](#attaching-the-csrf-filter-to-a-route)

```
Route::post('profile', array('before' => 'csrf', function()
{
	//
}));
```

#### Retrieving the CSRF token string:

[](#retrieving-the-csrf-token-string)

```
$token = Session::getToken();
```

> **Note:** You must specify a session driver before using the Laravel CSRF protection facilities.

*Further Reading:*

- [Route Filters](/docs/routing#filters)
- [Cross-Site Request Forgery](http://en.wikipedia.org/wiki/Cross-site_request_forgery)

Labels
------

[](#labels)

#### Generating a label element:

[](#generating-a-label-element)

```
echo Form::label('email', 'E-Mail Address');
```

#### Specifying extra HTML attributes for a label:

[](#specifying-extra-html-attributes-for-a-label)

```
echo Form::label('email', 'E-Mail Address', array('class' => 'awesome'));
```

> **Note:** After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.

Text, Text Area, Password &amp; Hidden Fields
---------------------------------------------

[](#text-text-area-password--hidden-fields)

#### Generate a text input element:

[](#generate-a-text-input-element)

```
echo Form::text('username');
```

#### Specifying a default value for a text input element:

[](#specifying-a-default-value-for-a-text-input-element)

```
echo Form::text('email', 'example@gmail.com');
```

> **Note:** The *hidden* and *textarea* methods have the same signature as the *text* method. You just learned three methods for the price of one!

#### Generating a password input element:

[](#generating-a-password-input-element)

```
echo Form::password('password');
```

Checkboxes and Radio Buttons
----------------------------

[](#checkboxes-and-radio-buttons)

#### Generating a checkbox input element:

[](#generating-a-checkbox-input-element)

```
echo Form::checkbox('name', 'value');
```

#### Generating a checkbox that is checked by default:

[](#generating-a-checkbox-that-is-checked-by-default)

```
echo Form::checkbox('name', 'value', true);
```

> **Note:** The *radio* method has the same signature as the *checkbox* method. Two for one!

File Input
----------

[](#file-input)

#### Generate a file input element:

[](#generate-a-file-input-element)

```
echo Form::file('image');
```

Drop-Down Lists
---------------

[](#drop-down-lists)

#### Generating a drop-down list from an array of items:

[](#generating-a-drop-down-list-from-an-array-of-items)

```
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'));
```

#### Generating a drop-down list with an item selected by default:

[](#generating-a-drop-down-list-with-an-item-selected-by-default)

```
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S');
```

Buttons
-------

[](#buttons)

#### Generating a submit button element:

[](#generating-a-submit-button-element)

```
echo Form::submit('Click Me!');
```

> **Note:** Need to create a button element? Try the *button* method. It has the same signature as *submit*.

Custom Macros
-------------

[](#custom-macros-1)

It's easy to define your own custom Form class helpers called "macros". Here's how it works. First, simply register the macro with a given name and a Closure:

#### Registering a Form macro:

[](#registering-a-form-macro)

```
Form::macro('myField', function()
{
	return '';
});
```

Now you can call your macro using its name:

#### Calling a custom Form macro:

[](#calling-a-custom-form-macro)

```
echo Form::myField();
```

---

Working With Strings
====================

[](#working-with-strings)

Contents
--------

[](#contents-1)

- [Capitalization, Etc.](#capitalization)
- [Word &amp; Character Limiting](#limits)
- [Generating Random Strings](#random)
- [Singular &amp; Plural](#singular-and-plural)
- [Slugs](#slugs)
- [Case Conversion](#case)
- [String Searching](#search)

Capitalization, Etc.
--------------------

[](#capitalization-etc)

The **Str** class provides three convenient methods for manipulating string capitalization: **upper**, **lower**, and **title**. These are more intelligent versions of the PHP [strtoupper](http://php.net/manual/en/function.strtoupper.php), [strtolower](http://php.net/manual/en/function.strtolower.php), and [ucwords](http://php.net/manual/en/function.ucwords.php) methods. More intelligent because they can handle UTF-8 input if the [multi-byte string](http://php.net/manual/en/book.mbstring.php) PHP extension is installed on your web server. To use them, just pass a string to the method:

```
echo Str::lower('I am a string.');
// i am a string.

echo Str::upper('I am a string.');
// I AM A STRING.

echo Str::title('I am a string.');
// I Am A String.
```

**Additional methods:**

`length( $string )`: Get the length of a string.

```
// Get the length of a string
$length = Str::length('Taylor Otwell');

// Get the length of a multi-byte string
$length = Str::length('Τάχιστη')
```

`upperWords( $string ):` Convert first letter of each word to uppercase.

Word &amp; Character Limiting
-----------------------------

[](#word--character-limiting)

#### Limiting the number of characters in a string:

[](#limiting-the-number-of-characters-in-a-string)

```
echo Str::limit("Lorem ipsum dolor sit amet", 10);
// Lorem ipsu...

echo Str::limitExact("Lorem ipsum dolor sit amet", 10);
// Lorem i...

// Limit the number of characters and append a custom ending
echo Str::limitExact('Taylor Otwell', 9, '---');
```

#### Limiting the number of words in a string:

[](#limiting-the-number-of-words-in-a-string)

```
echo Str::words("Lorem ipsum dolor sit amet", 3);
// Lorem ipsum dolor...

// Limit the number of words and append a custom ending
echo Str::words('This is a sentence.', 3, '---');
```

`wordwrap( $string, $length )`: Adds a space to a string after a given amount of contiguous, non-whitespace characters.

Generating Random Strings
-------------------------

[](#generating-random-strings)

#### Generating a random string of alpha-numeric characters:

[](#generating-a-random-string-of-alpha-numeric-characters)

```
echo Str::random(32);
```

#### Generating a random string of alphabetic characters:

[](#generating-a-random-string-of-alphabetic-characters)

```
echo Str::random(32, 'alpha');
```

Singular &amp; Plural
---------------------

[](#singular--plural)

#### Getting the plural form of a word:

[](#getting-the-plural-form-of-a-word)

```
echo Str::plural('user');
// users
```

#### Getting the singular form of a word:

[](#getting-the-singular-form-of-a-word)

```
echo Str::singular('users');
// user
```

#### Getting the plural form if specified value is greater than one:

[](#getting-the-plural-form-if-specified-value-is-greater-than-one)

```
echo Str::plural('comment', count($comments));
```

Slugs
-----

[](#slugs)

#### Generating a URL friendly slug:

[](#generating-a-url-friendly-slug)

```
return Str::slug('My First Blog Post!');
// my-first-blog-post
```

#### Generating a URL friendly slug using a given separator:

[](#generating-a-url-friendly-slug-using-a-given-separator)

```
return Str::slug('My First Blog Post!', '_');
// my_first_blog_post
```

Case Conversion
---------------

[](#case-conversion)

`ascii( $value )`: Convert a string to 7-bit ASCII.

`classify( $value )`: Convert a string to an underscored, camel-cased class name.

```
$class = Str::classify('task_name'); // Returns "Task_Name"

$class = Str::classify('taylor otwell') // Returns "Taylor_Otwell"
```

`camelCase( $value )`: Convert a value to camel case.

String Searching
----------------

[](#string-searching)

`is( $pattern, $value )`: Determine if a given string matches a given pattern.

`endsWith( $haystack, $needle )`: Determine if a given string ends with a given needle.

`startsWith( $haystack, $needle )`: Determine if a string starts with a given needle.

`contains( $haystack, $needle )`: Determine if a given string contains a given sub-string.

Additional Helper Methods
-------------------------

[](#additional-helper-methods)

`dd( $value )`: Dumps the given value. Execution will halt after call to this function.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

4859d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0754c69013ebfdf076adcef5f65b31df4bf0b454914707c026cdafd555bbde79?d=identicon)[laravelbook](/maintainers/laravelbook)

---

Top Contributors

[![laravelbook](https://avatars.githubusercontent.com/u/3158677?v=4)](https://github.com/laravelbook "laravelbook (19 commits)")[![andrew13](https://avatars.githubusercontent.com/u/764875?v=4)](https://github.com/andrew13 "andrew13 (2 commits)")[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (1 commits)")[![mul14](https://avatars.githubusercontent.com/u/113989?v=4)](https://github.com/mul14 "mul14 (1 commits)")

---

Tags

frameworklaravelstringhtmlformsupport

### Embed Badge

![Health badge](/badges/laravelbook-laravel4-powerpack/health.svg)

```
[![Health](https://phpackages.com/badges/laravelbook-laravel4-powerpack/health.svg)](https://phpackages.com/packages/laravelbook-laravel4-powerpack)
```

###  Alternatives

[htmlmin/htmlmin

HTMLMin Is A Simple HTML Minifier For Laravel 5

1.0k1.9M9](/packages/htmlmin-htmlmin)[dragon-code/support

Support package is a collection of helpers and tools for any project.

238.7M101](/packages/dragon-code-support)[laravel/surveyor

Static analysis tool for Laravel applications.

7639.0k7](/packages/laravel-surveyor)[lanin/laravel-api-exceptions

All in one solution for exception for JSON REST APIs on Laravel and Lumen.

40102.4k](/packages/lanin-laravel-api-exceptions)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
