cleaniquecoders/laravel-helper

使用Laravel独立包创建器构建

4.2.0 2024-03-21 03:52 UTC

README

Latest Stable Version Total Downloads Scrutinizer Code Quality License

关于您的包

为您的应用程序收集一系列助手。

安装

为了在您的Laravel项目中安装cleaniquecoders/laravel-helper,只需从您的终端运行composer require命令

composer require cleaniquecoders/laravel-helper

然后在您的config/app.php中将以下内容添加到providers数组中

CleaniqueCoders\LaravelHelper\LaravelHelperServiceProvider::class,

在相同的config/app.php中,将以下内容添加到aliases数组中

'LaravelHelper' => CleaniqueCoders\LaravelHelper\LaravelHelperFacade::class,

发布Laravel Helper配置文件

php artisan vendor:publish --tag=laravel-helper

使用方法

生成序列

generate_sequence(313)将生成000313。如果您想标准化生成序列号,这将非常有用。

缩写

abbrv('你的词')将生成YRWDS

您可以通过助手配置文件配置abbrv()助手。

FQCN(完全限定类名)

fqcn($user) - 将返回App\User。如果您正在处理多态关系,这将非常有用。

FQCN的slug名称

str_slug_fqcn($user) - 将生成app-user,FQCN的kebab case。如果您想有一个对象的可缩写名称,并将其用作数据库中的标识符,而不是FQCN,这将非常有用。

通知

您可以通过调用notify()助手简单地发送通知给用户。

// send by id
notify(1)
    ->subject('Laravel Helper')
    ->message('Sending notification via notify helper is awesome.')->send();

// you can send by email, but require to specify column name on second argument
notify('nasrulhazim.m@gmail.com', 'email')
    ->subject('Laravel Helper')
    ->message('Sending notification via notify helper is awesome.')
    ->send();

// Send with Subject and Message, CC and BCC
$cc = \App\Models\User::whereIn('id', [2,3,4])->get()->pluck('email')->toArray();
$bcc = \App\Models\User::whereIn('id', [5,6,7])->get()->pluck('email')->toArray();

notify(1)
   ->subject('Laravel Helper')
   ->message('Send notification via notify() helper is awesome and easy.')
   ->cc($cc)
   ->bcc($bcc)
   ->send();

// Send Notification with Subject, Message, Link.
notify(1)
   ->subject('Laravel Helper')
   ->message('Send notification via notify() helper is awesome and easy.')
   ->link('https://google.com')
   ->send();

// Send Notification with Subject, Message, Link and Custom Link Label.
notify(1)
   ->subject('Laravel Helper')
   ->message('Send notification via notify() helper is awesome and easy.')
   ->link('https://google.com')
   ->link_label('Google')
   ->send();

// Send Notification with Subject, Message, Link, Custom Link Label and Custom Template.
notify(1)
   ->subject('Laravel Helper')
   ->message('Send notification via notify() helper is awesome and easy.')
   ->link('https://google.com')
   ->link_label('Google')
   ->template('mail.custom')
   ->send();

// Send Notification with Subject, Message, Link, Custom Link Label, Custom Template and Mixed Data.
notify(1)
   ->subject('Laravel Helper')
   ->message('Send notification via notify() helper is awesome and easy.')
   ->link('https://google.com')
   ->link_label('Google')
   ->template('mail.custom')
   ->data($anything)
   ->send();

您可以将任何内容设置为数据 - 数组、对象、字符串等。

测试

要运行测试,请从您的终端键入vendor/bin/phpunit

要获得代码覆盖率,请确保安装PHP XDebug,然后运行以下命令

$ vendor/bin/phpunit -v --coverage-text --colors=never --stderr

贡献

感谢您考虑为cleaniquecoders/laravel-helper做出贡献!

错误报告

为了鼓励积极的合作,强烈建议进行拉取请求,而不仅仅是错误报告。“错误报告”也可以以包含失败测试的拉取请求的形式发送。

但是,如果您提交错误报告,您的问题应包含标题和问题的清晰描述。您还应包括尽可能多的相关信息和演示问题的代码示例。错误报告的目的是使您和其他人能够轻松地复制错误并开发修复方案。

请记住,错误报告是在希望有相同问题的其他人能够与您合作解决错误的情况下创建的。不要期望错误报告会自动看到任何活动,或者其他人会跳出来修复它。创建错误报告的目的是帮助您和其他人开始解决问题的道路。

编码风格

cleaniquecoders/laravel-helper遵循PSR-2编码标准和PSR-4自动加载标准。

您可以使用PHP CS Fixer来保持标准化的代码。PHP CS Fixer配置可以在.php_cs中找到。

许可

此包是开源软件,许可协议为MIT许可证