danpalmieri/jetstream-team-url

一个将当前团队显示为URL前缀的包。您必须安装启用团队功能的Laravel Jetstream。

v1.3 2024-05-03 19:01 UTC

This package is auto-updated.

Last update: 2024-09-03 19:45:45 UTC


README

Latest Version on Packagist GitHub Code Style Action Status

一个将用户的当前团队显示在URL中的包。非常适合生成永久链接并在方便时自动切换。您必须安装启用团队功能的Laravel Jetstream。

安装

您可以通过Composer安装此包

composer require danpalmieri/jetstream-team-url

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="jetstream-team-url-config"

这是已发布配置文件的内容

return [
    'url' => [
        'prefix' => 'teams', // the prefix for the team routes
        'team_attribute' => 'id', // the attribute to use for the team route
    ],

    'middleware' => \DanPalmieri\JetstreamTeamUrl\Middleware\VerifyOrSetCurrentTeamInRoute::class,
    
    'livewire_support' => true, // Add a persistent middleware to Livewire to support the team in the URL

    'on_denied' => [
        'strategy' => 'redirect', // abort|redirect
        'redirect' => [
            'to' => '/',
            'with' => [
                'key' => 'error',
                'value' => 'You are not allowed to access this team.',
            ],
        ],
        'abort' => [403, 'You are not allowed to access this team.'],
    ],

    'on_different_team' => [
        'strategy' => 'switch', // abort|switch
        'abort' => [403, 'You are not working on the right team.'],
    ],
];

使用方法

只需将useTeamInUrl()方法添加到您的路由组中。

Route::useTeamInUrl(function () {
    Route::get('/dashboard', fn () => view('dashboard')); // example.test/teams/2352/dashboard
});

您还可以获得currentTeamRedirect()方法。将此方法放在Route::useTeamInUrl()方法之外。

Route::currentTeamRedirect('_'); // example.test/_/posts/34 -> example.test/teams/2352/posts/34

行为

关于此包的一些注意事项

  • 如果用户已登录并且处于团队中(并且您使用的是命名路由),则此包会自动将团队ID(或其他属性)添加到URL中。
  • 它还会检查用户是否处于正确的团队。如果不是,它将重定向或终止。
  • currentTeamRedirect($char)方法将替换URL中的字符为当前团队ID(或其他属性)。

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全漏洞

有关如何报告安全漏洞的详细信息,请参阅我们的安全策略

致谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件