anthoz69/anter

此包是用于开发laravel的拼贴辅助函数和类

0.0.8 2021-10-17 09:00 UTC

README

Latest Version on Packagist Total Downloads StyleCI

此包收集了我经常在laravel中使用的常用方法和函数,如果你使用此包,它可能会随时破坏更改。请将其分叉到自己的存储库中,并在需要时提交一些PR以贡献酷炫功能。

安装

1 - 使用Composer安装包

composer require anthoz69/anter

包将自动注册其服务提供者。

注意:如果你使用Laravel 5.5,步骤2和3(提供者和别名)是不必要的。Dod包支持Laravel新的包发现

2 - 你需要更新应用程序配置以注册此包,使其可以被Laravel加载,只需更新你的config/app.php文件,在'providers'部分末尾添加以下代码

config/app.php

'providers' => [
    // other providers ommited
    anthoz69\anter\Providers\AntherServiceProvider::class,
],

使用方法

AnterStore Facade

在前端上传文件到laravel中保存文件,并在保存文件之前生成唯一的文件名。

AnterStore::store($path, $file)->save();
AnterStore::url($path);
AnterStore::delete($path);

AnterImg Facade

在前端上传文件到laravel中保存文件并调整图片大小。

// Store image in /storage/app/public/user/cover
// save() method will return full path of image.
$image = AnterStore::make('user/cover', $request->file('image'));
$image->crop(300, 450)->save(); // Crop image from center size 300px x 450px.
$image->fit(300, 300, true)->save(); // Resize and crop image to 300px x 300px and prevent up size image if set true.
$image->resize(300, true)->save(); // Resize to width 300px and prevent up size image if set true.
$image->width(); // Get width of image.
$image->height(); // Get height of image.

货币函数

2 => 2.00

4.75668 => 4.75

setCurrency($number, $percision = 2); // truncate and round
truncate($number, $percision = 2); // truncate and not round number

路由函数

isRoutePrefix 如果你的url以 /admin 或其他开始,将 active class 放置到HTML属性class中,这对于层次菜单很有用。

isRouteMatch('/admin/*', $class = 'active');

例如,你的url为 /admin/user/create

<li class="{{ isRouteMatch('/admin/*', 'active-patent-menu') }}"></li>

// output if url start with /admin/user
<li class="active-patent-menu"></li>

isRoute 当用户访问url且与 laravel路由名称 匹配时,将输出class。

isRoute($routeName = '', $class = 'active');

isRoute('user.create', 'active-color-menu'); // result: active-color-menu
isRoute('user.create'); // result: active

视频函数

从url中获取id,支持YouTube、Vimeo,如果格式错误将返回 null

getYoutubeId('https://www.youtube.com/watch?v=aAzUC8vNtgo'); // output: aAzUC8vNtgo
getVimeoId('https://vimeo.com/68529790'); // output: 68529790
getVideoProvider('https://www.youtube.com/watch?v=aAzUC8vNtgo'); // output: youtube

泰国国家格式的时间函数

将时间戳(laravel中的created_at、updated_at)发送到函数将返回字符串时间。

getTHMonth($index, $short = true);
getDateTH($strDate, $shortMonth = true, $time = false);
getTimeFromDate($strDate, $second = true);

例如。

getTHMonth(1); // มกราคม
getTHMonth(1, true); // ม.ค.

getDateTH('2019-07-17 16:07:42'); // 17 ก.ค. 2562
getDateTH('2019-07-17 16:07:42', false); // 17 กรกฏาคม 2562
getDateTH('2019-07-17 16:07:42', true, true); // 17 ก.ค. 2562 16:07

getTimeFromDate('2019-07-17 16:07:42'); // 16:07
getTimeFromDate('2019-07-17 16:07:42', true); // 16:07:42

安全

如果你发现任何与安全相关的问题,请打开问题或发送一些酷炫的PR给我。

鸣谢

贡献

请参阅contributing.md以获取详细信息和一个待办事项列表。

许可证

许可证是MIT。请参阅许可证文件以获取更多信息。