Composer 包使用
laravel/socialite
提供与 Facebook,微博,谷歌,LinkedIn,GitHub等 OAuth认证。
github 地址
https://github.com/laravel/socialite
安装
composer require laravel/socialite
guzzle/guzzle | guzzlehttp/guzzle
是一个PHP HTTP客户端,可以很容易地发送HTTP请求和琐碎与Web服务集成
github 地址
https://github.com/guzzle/guzzle
安装
见github
文档
http://guzzlephp.org/
版本
Version | Status | Packagist | Namespace | Repo | Docs | PSR-7 | PHP Version |
---|---|---|---|---|---|---|---|
3.x | EOL | guzzle/guzzle | Guzzle | v3 | v3 | No | >= 5.3.3 |
4.x | EOL | guzzlehttp/guzzle | GuzzleHttp | v4 | N/A | No | >= 5.4 |
5.x | Maintained | guzzlehttp/guzzle | GuzzleHttp | v5 | v5 | No | >= 5.4 |
6.x | Latest | guzzlehttp/guzzle | GuzzleHttp | v6 | v6 | Yes | >= 5.5 |
Baum\Node
Baum是Laravel 5的Eloquent ORM 的嵌套集模式的实现, 无限级分类。
github 地址
https://github.com/etrepat/baum
使用实例
- ancestorsAndSelf 获取所有祖先链节点,包括当前链节点。
- ancestors 获取所有祖先链节点,不包括当前链节点。
$articleCats = $articleCats->where('id', 5)->first()->ancestorsAndSelf()->get()->toArray();
Array
(
[0] => Array
(
[value] => 1
[parent_id] => 0
[label] => 第一个一级分类
)
[1] => Array
(
[value] => 4
[parent_id] => 1
[label] => 二级分类
)
[2] => Array // 这个是自己
(
[value] => 5
[parent_id] => 4
[label] => 三级分类
)
)
- siblingsAndSelf 获取自己兄弟接点,同一父亲,包括自己
- siblings 获取自己兄弟接点,同一父亲,不包括自己
$articleCats = $articleCats->where('id', 1)->first()->siblingsAndSelf()->get()->toArray();
Array
(
[0] => Array
(
[value] => 1
[parent_id] => 0
[label] => 第一个一级分类
)
[1] => Array // 自己
(
[value] => 2
[parent_id] => 0
[label] => 第二个一级分类
)
[2] => Array
(
[value] => 3
[parent_id] => 0
[label] => 第三个一级分类
)
)
- leaves 最后一个没有孩子的节点
$articleCats = $articleCats->where('id', 1)->first()->leaves()->get()->toArray();
Array
(
[0] => Array // 没有子节点
(
[parent_id] => -> ...->... 1
[value] => 5
[label] => 三级分类
)
)
- descendantsAndSelf 所有子节点,包括自己
- descendants 所有子节点,不包括自己
$articleCats = $articleCats->where('parent_id', 0)->first()->descendantsAndSelf()->get()->toArray();
Array
(
[0] => Array // 自己
(
[parent_id] => 0
[value] => 1
[label] => 第一个一级分类
)
[1] => Array
(
[parent_id] => 1
[value] => 4
[label] => 二级分类
)
[2] => Array
(
[parent_id] => 4
[value] => 5
[label] => 三级分类
)
)
- 获取所有 分类包括所有子节点
- toHierarchy() 按照 层级组合结果
$articleCats = ArticleCat::where('parent_id', 0)->get();
foreach($articleCats as $key => $descendant) {
$articleCats[$key]->children = array_values($descendant->getDescendants()->toHierarchy()->toArray());
}
Array
(
[0] => Array
(
[id] => 1
[parent_id] => 0
[value] => 1
[label] => 第一个一级分类
[children] => Array
(
[0] => Array
(
[id] => 4
[parent_id] => 1
[value] => 4
[label] => 二级分类
[children] => Array
(
[0] => Array
(
[id] => 5
[parent_id] => 4
[value] => 5
[label] => 三级分类
[children] => Array
(
)
)
)
)
)
)
[1] => Array
(
[id] => 2
[parent_id] => 0
[value] => 2
[label] => 第二个一级分类
[children] => Array
(
[0] => Array
(
[id] => 6
[parent_id] => 2
[value] => 6
[label] => 又一个二级分类
[children] => Array
(
)
)
)
)
[2] => Array
(
[id] => 3
[parent_id] => 0
[children] => Array
(
)
[value] => 3
[label] => 第三个一级分类
)
)
simplesoftwareio/simple-qrcode
插件是基于 Laravel 5 的二维码生成插件
github 地址
https://github.com/SimpleSoftwareIO/simple-qrcode
使用实例
// 生成二维码,保存成 svg ,svg 为默认格式
QrCode::generate('Hello,LaravelAcademy!', public_path('qrcodes/qrcode.svg'));
// 生成png 格式二维码,保存到本地,并且 中间有图标,大小,颜色,背景,边距,编码
QrCode::format('png')
->encoding('UTF-8')
->size(200)
->color(255, 0, 255)
->backgroundColor(255, 255, 0)
->margin(1)
->merge('/public/images/no_pic.jpg', .15)
->generate('Hello,LaravelAcademy!', public_path('qrcodes/qrcode.png'));
// 生成 png 格式的二维码 以png 方式返回http 相应
$qrcode = QrCode::format('png')->size(300)->generate('this is png encode!');
return response($qrcode, 200)->header('Content-Type', "png");
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: