vi-kon / laravel-utilities
Utilities for Laravel 5
Installs: 27 998
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
- illuminate/support: ~5.0
- symfony/console: ^2.6
Suggests
- vi-kon/laravel-smarty-view: Smarty template engine for Laravel 5
This package is not auto-updated.
Last update: 2021-03-05 21:41:23 UTC
README
Utilities for Laravel 5. View helpers and other usefull classes.
Table of contents
Known issues
None
Todo
- Fix incoming bugs
- Finish documentation
Changes
Version 2.1
- The Seeder class functionality replaced by ConsoleProgressbar trait
Version 2.0
- Laravel 5 support (requirement)
- Controller class removed (Laravel 5 supports validation via FormRequest classes)
- New middleware features (IsAjax)
- Code optimization with Laravel 5 new features and conventions
Installation
Base
To your composer.json
file add following lines:
// to your "require" object "vi-kon/laravel-utilities": "2.*"
In your Laravel 5 project add following lines to app.php
:
// to your providers array 'ViKon\Utilities\UtilitiesServiceProvider',
Middleware
To use middleware class assigned to route need to assign short-hand key to middleware
property of your app/Providers/RouteServiceProvider
class:
// to your middleware array 'ajax' => 'ViKon\Utilities\Middleware\IsAjax',
Views
- html5-layout - HTML 5 layout
html5-layout
There are two templates. One for Blade template engine and one for Smarty template engine.
Note: html5-layout.tpl requires Smarty functions implemented in vi-kon/laravel-smarty-view package.
Avalaible blocks / sections:
Name | Description |
---|---|
author | Author metadata |
body | Empty block in body root |
description | Description metadata |
head | Empty block for other head stuff |
scripts | Scripts at after closing body tag |
scripts-head | Empty block to include header scripts |
styles | Empty block to include stylesheets |
title | Page title |
viewport | Viewport meta data |
Block / section definitions:
author
<!-- ... other head stuff ... --> <meta name="author" content="@yield('author', 'Kovács Vince')"/> <!-- ... other head stuff ... -->
<!-- ... other head stuff ... --> <meta name="author" content="{block name="author"}Kovács Vince{/block}"> <!-- ... other head stuff ... -->
body
<body> @yield('body') </body>
<body> {block name="body"}{/block} </body>
description
<!-- ... other head stuff ... --> <meta name="description" content="@yield('description')"/> <!-- ... other head stuff ... -->
or
<!-- ... other head stuff ... --> <meta name="description" content="{block name="description"}{/block}"> <!-- ... other head stuff ... -->
head
<head> <!-- ... other head stuff ... --> @yield('head') </head>
or
<head> <!-- ... other head stuff ... --> {block name="head"}{/block} </head>
scripts
<!-- ... body inner ... --> </body> @yield('scripts') </html>
or
<!-- ... body inner ... --> </body> {block name="scripts"}{/block} </html>
scripts-head
<head> <!-- ... other head stuff ... --> @yield('scripts-head') <!-- ... other head stuff ... --> </head>
or
<head> <!-- ... other head stuff ... --> {block name="scripts-head"}{/block} <!-- ... other head stuff ... --> </head>
styles
<head> <!-- ... other head stuff ... --> @yield('styles') <!-- ... other head stuff ... --> </head>
or
<head> <!-- ... other head stuff ... --> {block name="styles"}{/block} <!-- ... other head stuff ... --> </head>
title
<!-- ... other head stuff ... --> <title>@yield('title', 'HTML 5 Layout')</title> <!-- ... other head stuff ... -->
or
<!-- ... other head stuff ... --> <title>{block name="title"}HTML 5 Layout{/block}</title> <!-- ... other head stuff ... -->
viewport
<head> <!-- ... other header stuff ... --> @section('viewport') <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> @show <!-- ... other header stuff ... --> </head>
or
<head> <!-- ... other header stuff ... --> {block name="viewport"} <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> {/block} <!-- ... other header stuff ... --> </head>
Usage
Example "app-layout.tpl"
{extends file="view:utilities::html5-layout"} {block name="title"}{strip} {lang}app.title{/lang} {/strip}{/block} {block name="description"}{strip} {lang}app.description{/lang} {/strip}{/block} {block name="styles"}{strip} {html_style _url="vendor/bootstrap/css/bootstrap.min.css"} {html_style _url="vendor/bootstrap-tokenfield/bootstrap-tokenfield.min.css"} {/strip}{/block} {block name="scripts-head" append}{strip} {html_script _url="vendor/jquery/jquery-2.1.0.min.js"} {html_script _url="vendor/bootstrap/js/bootstrap.min.js"} {html_script _url="vendor/bootstrap-tokenfield/bootstrap-tokenfield.min.js"} {/strip}{/block} {block name="scripts" append}{strip} {html_script _url="js/bootstrap-setup.js"} {/strip}{/block} {block name="body"}{strip} <div class="container"> {* Page menu *} <div class="page-header"> <div class="row"> <div class="col-sm-8"> <h1>{lang}app.header.title{/lang}</h1> <p class="lead text-muted">{lang}app.header.title-lead{/lang}</p> </div> {if $user !== null} <div class="col-sm-4 text-right"> {$user['username']} | <a href="{url _name="user.ajax.modal.edit"}" type="button" rel="tooltip" data-toggle="modal" data-target="#modal"> {lang}app.header.btn.settings{/lang} </a> | <a href="{url _name="auth.logout"}">{lang}app.header.btn.logout{/lang}</a> </div> {/if} </div> </div> </div> <div class="container"> {* Block container for subpage content *} {block name="container"}{/block} </div> {/strip}{/block}
Classes
- Migration - helper methods for database migration
Traits
- ConsoleProgressbar - progressbar for console applications
ConsoleProgress trait
This trait help display a progressbar on console:
Output
############-------------------------------------- 24.54% (124,752/508,331)
Usage
// Initialize progressbar $this->initProgressbar(); // Reset progress and output a message $this->startProgress('Seed agt_agent_types table'); // Set progressbar elements $this->setProgressMax(12); // ... // Make step in progressbar $this->progress();
Middleware
Utilities middleware classes allow different features.
- IsAjax - check if current request is ajax request or not
IsAjax middleware
Check if current request is ajax request or not. If request is not ajax request, then throws NotFoundHttpException
exception.
Usage
$options = [ 'middleware' => 'ajax', ]; Route::get('URL', $options);
Helpers
Helper functions are shortcuts or aliases for app functions and methods.
json_response function
json_response
function is alias for new JsonResponse
.
License
This package is licensed under the MIT License