danilpetrenko/laravel-helpers
最新稳定版本:v1.0.1
Composer 安装命令:
composer require danilpetrenko/laravel-helpers
包简介
Package for generating helper functions based on static classes
README 文档
README
LaravelHelpers package lets you write your helpers using static class methods and then use them whereever you want in Laravel helpers style
Installation:
composer require danilpetrenko/laravel-helpers
php artisan vendor:publish
You can create Helpers folder inside your app folder and then start writing helpers Note that you must always specify return type of your static method, otherwise no return will be provided ExampleHelper:
static function divideByFive(int $number): int
{
return (int)$number/5;
}
Then you're supposed to run command
php artisan generate-helpers-autoload
will generate following function inside bootstrap/helpers.php:
function divideByFive(int $number): int{
return App\Helpers\TestHelper::divideByFive($number);
}
Then you should add bootstrap/helpers.php into autoload section of your composer.json file:
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"files": [ "bootstrap/helpers.php" ]
},
Now you are able to use your helper inside any class or view like Laravel's default helper
<h3>{{divideByFive(25)}}<h3>
PHPDocs will be also copied to autoload file, so helper usage explanation will be available when using function.
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2023-11-17