oburatongoi/productivity

生产力 - Artisan Pixelworks 的生产力 API

0.4.45 2018-06-06 00:45 UTC

README

安装

兼容 Laravel 5。安装时运行

$ composer install oburatongoi/productivity.

接下来,将服务提供者添加到 app/config.app 文件中的提供者数组中

Oburatongoi\Productivity\Providers\ProductivityServiceProvider::class,

在你的 .env 文件中,添加以下变量

SESSION_DOMAIN=.your-domain.com 注意域名名前的 '.'

PRODUCTIVITY_LOGO=logo-text 默认为 'Productivity'

PRODUCTIVITY_DOMAIN=your-domain.com

PRODUCTIVITY_SUBDOMAIN=productivity

如果使用 Scout 与 Algolia,设置以下环境变量

FOLDER_INDEX_NAME=the-name-of-your-folder-index 默认为 prod_FOLDERS

CHECKLIST_INDEX_NAME=the-name-of-your-folder-index 默认为 prod_CHECKLISTS

确保更新你的 DNS 'A' 或 'CNAME' 设置以包括新名称,如果你没有通配符子域名加密,请为所需的子域名添加 SSL 加密。

接下来,发布包的视图、迁移和路由

$ php artisan vendor:publish

你需要强制发布生产力配置。请注意,这将添加或覆盖配置文件夹中的以下文件:productivity.php、fakeid.php 和 javascript.php

php artisan vendor:publish --tag=productivity --force

接下来,将 Productive 特性添加到你的应用程序的用户模型中

use Oburatongoi\Productivity\Traits\Productive;


class User extends Authenticatable
{
    use Notifiable, Productive;

    // ... User class methods
}

为了正确处理某些异常,将以下内容添加到你的 app\Exceptions\Handler.php 文件中

use Illuminate\Session\TokenMismatchException as TokenMismatchException;
use AlgoliaSearch\AlgoliaException as AlgoliaException;

use Bugsnag;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
        \Illuminate\Session\TokenMismatchException::class,
        \AlgoliaSearch\AlgoliaException::class,
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $exception
     * @return void
     */
    public function report(Exception $exception)
    {
        Bugsnag::notifyException($exception);
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {

        if ($exception instanceof TokenMismatchException) {
            Bugsnag::notifyException($exception);

            if ($request->expectsJson()) return response()->json([
                'tokenMismatch' => true,
                'input' => $request->except(['password']),
                'url' => $request->fullUrl(),
                'method' => $request->method(),
                'token' => csrf_token()
            ]);
        }

        if ($exception instanceof AlgoliaException) {
            Bugsnag::notifyException($exception);

            if ($request->expectsJson()) return response()->json([
                'algoliaException' => true,
                'input' => $request->except(['password'])
            ]);
        }

        return parent::render($request, $exception);
    }

最后,运行迁移以将生产力文件夹添加到数据库中。请注意,生产力的所有表都有 productivity_ 前缀,所以请确保你的数据库中没有命名冲突

$ php artisan migrate

入门指南

当将生产力添加到新的 Laravel 安装中时,请考虑以下操作

  • 更改 config/app 中的应用程序名称
  • 安装 Bugsnag
  • 安装和配置 Algolia
  • 安装和配置 Redis
  • 安装和配置 JosephSilber/bouncer 包