sukohi/caruta 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sukohi/caruta

Composer 安装命令:

composer require sukohi/caruta

包简介

A PHP package mainly developed for Laravel to generate sort link(s).

README 文档

README

A PHP package mainly developed for Laravel to generate sort link(s).
(This is for Laravel 5+. For Laravel 4.2)

alt text alt text

Installation

Add this package name in composer.json

"require": {
  "sukohi/caruta": "2.*"
}

Execute composer command.

composer update

Register the service provider in app.php

'providers' => [
    ...Others...,  
    Sukohi\Caruta\CarutaServiceProvider::class,
]

Also alias

'aliases' => [
    ...Others...,  
    'Caruta'   => Sukohi\Caruta\Facades\Caruta::class
]

Usage

Minimal way

{{ \Caruta::links('your-column-name') }}

(example)
alt text

with Options

echo \Caruta::url('http://example.com')  
    ->text('↑', '↓')  
    ->appends([
		'key1' => 'value1',  
		'key2' => 'value2',  
		'key3' => 'value3'  
	])
	->keys('order', 'direction')
	->links('column_name', $separator = ''); 
  • All methods except links() are optional. See methods

Single Text Way

If you set the third argument like the below, only one link will be displayed.

\Caruta::text(
    '<i class="fa fa-sort-asc"></i>',  
    '<i class="fa fa-sort-desc"></i>',  
    '<i class="fa fa-sort"></i>'
);

(example)

alt text

Sort with model
With model(Eloquent), you can automatically set "ORDER BY" like the below.

$items = \App\Item::select('id', 'title');
$items = \Caruta::sort($items, 
    ['id', 'title', 'created_at'], 
    ['updated_at', 'asc']
);
dd($items->get()->toArray());
  • The second argument(Array) means that except specific column name(s) will be ignored to set "ORDER BY" for secure.
  • The third argument(Array) will be used for default. And direction canbe asc and desc

Note: If you changed the parameter name "ORDER BY" to other using keys() method, you also need to set it in this case as well.

Methods

  • url($url)

$url is base URL that will be included in href property.

  • text($one, $two)

$one and $two are text that will be included in link tag.

e.g. <a href="****">YOUR-TEXT</a>

  • appends($values)

$values is additional values that you want to include in link URL.

e.g. http://example.com?orderby=*****&direction=asc&YOUR-KEY=YOUR-VALUE

License

This package is licensed under the MIT License.

Copyright 2014 Sukohi Kuhoh

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-09-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固