运动式/sportily-laravel-support

一个用于使用 Laravel 创建 Sportily 网站的辅助类库。

1.0.5 2017-09-25 12:36 UTC

This package is auto-updated.

Last update: 2024-09-13 10:01:23 UTC


README

安装

Composer 是安装此包的推荐方式。将以下行添加到您的 composer.json 文件中

"sportily/sportily-laravel-support": "dev-master@dev"

然后运行 composer update 获取包。

一旦 Composer 安装了包,请将以下行添加到位于您的 config/app.php 文件中的 providers 数组中

Sportily\Support\SupportServiceProvider::class,

接下来,运行 php artisan vendor:publish 来发布此包的配置。

中间件

在特定环境中强制 HTTPS

我们建议所有生产环境都通过 https 连接运行,为此请在 Kernel.php 中的 'web' 下注册中间件

'web' => [
    \App\Http\Middleware\EncryptCookies::class,
    ...
    ...
    \Sportily\Support\Middleware\ForceHttps::class,
],

将需要保护的环境添加到 sportily-support.php 中。

    'secure-envs' => ['prod', 'production']

获取组织 ID

为了在控制器方法中使用组织 ID,它可以从请求中提取,如下例所示。

public function getIndex(Request $request) {
    $posts = $this->posts->all([
        'organisation_id' => $request->organisation['id'],
        'status' => 'published'
    ]);
    return view('posts', ['posts' => $posts]);
}

固定 ID

基于 URL 前缀的 ID

基于主机的 ID

在中间件组 require-dev 中注册 HostBasedOrganisationId

'sportily.private' => [
    \Sportily\OAuth\Middleware\OAuthMiddlewarePrivate::class,
    \Sportily\Support\Middleware\HostBasedOrganisationId::class,
    \Sportily\Support\Middleware\AugmentRequestWithOrganisation::class,
],

'sportily.public' => [
    \Sportily\OAuth\Middleware\OAuthMiddlewarePublic::class,
    \Sportily\Support\Middleware\HostBasedOrganisationId::class,
    \Sportily\Support\Middleware\AugmentRequestWithOrganisation::class,
]