Laravel H package
Laravel H is a helper package for Laravel Framework. Helper functions are really a lifesaver and useful for productivity. Making form is common task either we make a website or application and the Laravel H package provides frequently used helper functions & form builder functions for making HTML form with a clean and easy syntax.
GitHub repository: Laravel H
Installation
composer require haruncpi/laravel-h
Helpers
You can use all helper class method by H::method() or h()->method()
Example
| H::isLoggedIn() | h()->isLoggedIn() |
| H::numToWord(12.23) | h()->numToWord(12.23) |
Available Helper Methods
isLocalhost() - Check app is running on localhost or not.
H::isLocalhost() //output true
isLoggedIn($guard) - Check user is logged in or not. $guard by default null.
H::isLoggedIn() //output false
H::isLoggedIn('customer'); // for specific auth guard //output true
getUsername($guard) - Get the current logged in the user name. $guard by default null.
H::getUsername() //output Jhon Doe
getUserId($guard) - Get the current logged in user id. $guard by default null.
H::getUserId() //output 1
getUserEmail($guard) - Get the current logged in the user email address. $guard by default null.
H::getUserEmail() //output 1
getCurrentUser($guard) - Get the current logged in user. $guard by default null.
H::getCurrentUser()
toMoney($amount, $decimal = 2) - Get number to a currency format.
H::toMoney(200)
//output 200.00
H::toMoney(12.568)
//output 12.57
numberToWord($amount, $option = ['decimal' => 'dollar', 'fraction' => 'cents']) - Get number to words string.
H::numberToWord(200)
//output two hundred
H::numberToWord(200.12)
//output two hundred dollar one two cents
Form Helpers
You can use all class method by F::method() or f()->method()
Example
| F::text('name') | f()->text('email') |
| F::email('email') | f()->email('email') |
Available Form Helper Methods
open($options) - Open form tag.
F::open(['url'=>'submit'])
/** output
<form action="example.com/submit" method="POST">
<input type="hidden" name="_token" value="FwrnW3SOkLHKHsJctWnCeyZrOFtW6UtSHRf5XGrv"/>
*/
close() - Close form tag.
F::close() //output </form>
label($name) - Input label.
F::label('name') //output <label for="name">Name</label>
submit($value, $attr = []) - Form submit button.
F::submit('Save') //output <input type="submit" value="Save"/>
text($name, $value = null, $attr = []) - Form text box.
F::text('first_name')
//output <input type="text" name="first_name"/>
F::text('first_name', $data->name, ['class'=>'form-control'] )
//output <input type="text" name="first_name" value="Jhon Doe" class="form-control"/>
email($name, $value = null, $attr = []) - Form email type input box.
F::email('user_email') //output <input type="email" name="user_email"/>
password($name, $value = null, $attr = []) - Form password type input box.
F::password('password') //output <input type="password" name="password"/>
number($name, $value = null, $attr = []) - Form number type input box.
F::number('roll') //output <input type="number" name="roll"/>
hidden($name, $value = null, $attr = []) - Form hidden input box.
F::number('user_type') //output <input type="hidden" name="user_type"/>
file($name, $value = null, $attr = []) - Form file input.
F::file('photo') //output <input type="file" name="photo"/>
checkbox($name, $value = null, $attr = []) - Form checkbox
F::checkbox('is_admin')
radio($name, $value = null, $attr = []) - Form radio button
F::radio('active')
textarea($name, $value = null, $attr = []) - Form textarea.
F::textarea('description') //output <textarea name="description"></textarea>
select($name,$list,$selected,$attr) - Form select box.
$list = [1 => 'Jhon', 2 => 'Adam'];
F::select('user_id',$list,null);
/** output
<select name="user_id">
<option value="1">Jhon</option>
<option value="2">Adam</option>
</select>
*/
tel($name, $value = null, $attr = []) - Form input for telephone
F::tel('phone')
datetime($name, $value = null, $attr = []) - Form input for datetime
F::datetime('entery_on')
date($name, $value = null, $attr = []) - Form input for date
F::date('trx_date')
time($name, $value = null, $attr = []) - Form input for time
F::time('arrival_time')
week($name, $value = null, $attr = []) - Form input for week
F::week('week')