Wallogit.com
2017 © Pedro Peláez
Basic tools for building reports
Basic tools for building reports, (*1)
composer require binarycabin/laravel-reporting
Provides a scope to pass sortable values to a query:, (*2)
// (/users?sort=last_name&sort_order=ASC) $users = \App\User::sort($request->all())->get();
On your model, add the properties below to set the default sorting when none is passed:, (*3)
protected $sortFieldDefault = 'id'; protected $sortOrderDefault = 'ASC';, (*4)
Provides scopes to add filtering to your query:, (*5)
\App\User::filter($request->all())->get();
On your model, add a filterable property to determine all columns allowed to be filtered:, (*6)
protected $filterable = [
'first_name',
'last_name',
'global',
];
If a scope with the filterable name exists, it will be used in the filter. A scope "global" is provided in the trait. This will look through all fields in your "filterableGlobal" array for the passed query, (*7)
protected $filterableGlobal = [
'first_name',
'company',
];
\App\User::filter(['global'=>'ABC Company'])->get();
A sortable button is included to pass the "sort" and "sort_order" request values when viewing a table:, (*8)
<th>@include('reporting::components.sort-button',['sortField'=>'created_at']) Date Created</th>
An extendable controller is also available, which provides basic CRUD operation, along with default Sort/Filter functionality. To use this controller, simply create a controller extending it and passing available properties shown below:, (*9)
<?php
namespace App\Http\Controllers\Manage\Users;
use BinaryCabin\LaravelReporting\Http\Controllers\BaseManageController;
class UserController extends BaseManageController
{
protected $modelClass = \App\User::class;
protected $baseTitlePlural = 'Users';
protected $baseTitleSingular = 'User';
protected $variableNamePlural = 'users';
protected $variableNameSingular = 'user';
protected $baseRoute = 'manage/user';
protected $viewIndex = 'manage.user.index';
protected $viewCreate='manage.user.create';
protected $viewEdit='manage.user.edit';
}