tommyys / laravel_library
该包最新版本(1.4.13)没有可用的许可证信息。
为Axstarzy Dot Com提供的默认Laravel库,包括最常用的库、插件、辅助类和迁移文件
1.4.13
2020-09-15 06:36 UTC
Requires
- php: ^7.0
- funkjedi/composer-include-files: ^1.0
- guzzlehttp/guzzle: ^6.2
- intervention/image: ^2.4
- laravelcollective/html: >=5.1.0
This package is auto-updated.
Last update: 2024-09-15 15:28:13 UTC
README
为Axstarzy Dot Com提供的默认Laravel库,包括最常用的库、插件、辅助类和迁移文件
入门
请注意,该包正在持续开发和更新。如果您对该包有任何改进建议,请提出。
该包适用于Laravel Framework 5.5 LTS及以上版本。
以下包将被自动安装
- guzzlehttp/guzzle^6.3
- intervention/image^2.4
- laravelcollective/html^5.4.0
- funkjedi/composer-include-files^1.0,
包含辅助类
- 操作日志
- 错误日志
包含辅助函数
- sqlLog
- 自定义翻译
- getStatusLabel
先决条件
- PHP 7.0及以上
- Laravel 5.5及以上
安装
- 在项目中安装包
composer require tommyys/laravel_library
- 将提供者添加到
config/app.php的providers数组中
'providers' => [ // ... Collective\Html\HtmlServiceProvider::class, Intervention\Image\ImageServiceProvider::class, // ... ],
- 将类别名添加到
config/app.php的aliases数组中
'aliases' => [ // ... 'Form' => Collective\Html\FormFacade::class, 'Html' => Collective\Html\HtmlFacade::class, 'Image' => Intervention\Image\Facades\Image::class, // ... ],
- 要使用包含的辅助类,将此行添加到您的项目
composer.json中。
"extra": { ... "include_files": [ "vendor/tommyys/laravel_library/src/Helper.php" ] },
-
运行
composer dumpautoload -
运行
php artisan migrate以迁移所需的表
使用库
要使用包含的类,在控制器/命令的顶部包含命名空间。
... use Axstarzy\LaravelLibrary\ActionLog; use Axstarzy\LaravelLibrary\ErrorLog; use Axstarzy\LaravelLibrary\Telegram; ...
以下是可用的类
- ActionLog
- ErrorLog
- Telegram
然后您可以在控制器/命令中像使用辅助类一样正常使用它。
//create new action log $log = ActionLog::createRecord($request, $user); //$user is optional, if variable not passed it will use auth()->user() by default //check time gap between last request $gap = ActionLog::check30sGap($request);
要设置Telegram,将以下变量添加到您的 .env 文件中
TELEGRAM_NOTI_GROUP=-123123123
TELEGRAM_BOT_ID=botid
class TestController extends Controller { public function foo(){ sqlLog(ActionLog::where('user_id', 1)); } }
辅助
trans()
此包包含更新的 trans 函数,您必须已将 vendor/tommyys/laravel_library/src/Helper.php 添加到 composer.json 中才能使其生效。
示例
<span class="m-menu__link-text">
{{trans('string.Stock')}}
</span>
输出
<span class="m-menu__link-text">
Stock
</span>
output()
此函数将同时运行 echo 和 Log::info。
sqlLog()
接受模型/eloquent对象作为输入。此辅助函数将生成包含参数的完整SQL查询,以便于在MySQL中轻松进行故障排除。
示例
$userID = 123; sqlLog(ActionLog::where('user_id', $userID));
输出
select * from `action_log` where `user_id` = "123"
roundDownDecimal($number, $decimals = 2, $dec_point = '.', $thousands_point = ',')
此辅助函数类似于 number_format,但不会向上舍入小数。
示例
echo roundDownDecimal(200.1779, 2); #returns 200.17 echo roundDownDecimal(200.175,2); #returns 200.17 echo roundDownDecimal(200.172,2); #returns 200.17