定制 ilkermutlu/laravel-gloss 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ilkermutlu/laravel-gloss

Composer 安装命令:

composer require ilkermutlu/laravel-gloss

包简介

This package is a helper to create glossary-like views.

关键字:

README 文档

README

A simple Laravel5 package to create "glossary-like" views.

Many people would find this package a "trifle", but I find myself creating "glossary-like" views quite often, so I decided to roll out this package as a little helper.

This little package adds the "Gloss" Laravel facade, which takes in an array or a collection of query results, and groups them by the first letter of a specified label field (defaults to 'name') for use in views.

Bootstrap compliant template generation will hopefully be on the next update.

All ideas, contributions and criticism are welcome.

Installation

composer require ilkermutlu/laravel-gloss

In config/app.php, add the following line to the providers array:

'Ilkermutlu\Gloss\GlossServiceProvider'

And the following line to the `````aliases```` array:

'Gloss' => 'Ilkermutlu\Gloss\GlossFacade'

Usage

Import the facade in your script:

use Gloss;

You'd normally use this for a glossary of a set of words but, let's consider another scenario: you might want to have a contacts page grouped by letters.

Let's assume you have a person table and a full_name column in that table.

// Get the records
$records = \DB::select(\DB::raw('SELECT id, full_name FROM person'));

// Create the glossary data set
$gloss = Gloss::createFrom($records);
// Set the name attribute
$gloss->setName('full_name');
// Make the dataset
$people = $gloss->make();

Alternatively, you can chain the methods:

$gloss = Gloss::createFrom($records)->setName('full_name')->make();

which will provide you with an array the result set you provided, grouped by distinct first letters of the records.

TODO: (I will be adding functionality to automatically generate bootstrap compliant views which you can inject to your layouts as soon as I have some time, feel free to do it and create a pull request before I get to it!)

Until then; You can use the data in your views, just like you would with any array of data.

@foreach ($people as $letter => $person)
  <a href="#yourlinkhere">{{ $letter }}</a>
@endforeach

@foreach ($people as $letter => $person)
  <h1>{{ $letter }}</h1>
  <a href="/yourlinkhere/{{ $person->id }}">{{ $person->full_name }}</a>
@endforeach

统计信息

  • 总下载量: 45
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-08