grantholle/reaction

在Laravel 5中获取反应

1.2 2017-07-15 07:15 UTC

This package is auto-updated.

Last update: 2024-08-28 23:58:19 UTC


README

基于事件类型(正面、负面、不安全)生成反应

安装

通过Composer包含此包...

composer require grantholle/reaction

config/app.php中添加服务提供者...

'providers' => [
  ...
  Some\Kind\Of\ReactionServiceProvider::class
  ...
];

用法

简单使用react()辅助函数来生成随机反应。我喜欢将它与Laracast的Flash包结合使用,以便轻松、有趣地发送闪存消息。

react('positive'); // <strong>Boom!</strong>
react('bad'); // <strong>Yikes!</strong>
react('unsafe'); // <strong>Heads up!</strong>

// Using chaining
react()->positive(); // <strong>Great!</strong>
react()->bad(); // <strong>Darn!</strong>
react()->unsafe(); // <strong>Easy!</strong>

// Don't wrap it in <strong/>
react('positive', false);
react(null, false)->positive();

💯

// A controller function, for example
public function update(Request $request, Model $model)
{
  $model->update($request->all());
  $message = react()->positive() . ' The model has been updated successfully.';
  // <strong>Super!</strong> The model has been updated successfully.

  flash($message)->success();

...