danpalmieri / jetstream-team-url
一个将当前团队显示为URL前缀的包。您必须安装启用团队功能的Laravel Jetstream。
v1.3
2024-05-03 19:01 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
一个将用户的当前团队显示在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)。有关更多信息,请参阅许可文件。