the-3labs-team / nova-redirector-seo
Laravel Nova 的 SEO 重定向器
Requires
- php: ^8.1|^8.2|^8.3
- illuminate/contracts: ^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.13.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-18 14:27:47 UTC
README
NovaRedirectorSEO 是 Laravel Nova 的全功能 SEO 包。它提供了一种简单的方式来管理您的 SEO 重定向。
为什么选择 NovaRedirectorSEO?
- 预配置的 Laravel Nova 资源,您只需安装、注册和配置该包。
- 中间件 来处理重定向,您可以在路由或控制器中使用它。
- 缓存支持,根据您的配置,该包将缓存重定向。此外,当您创建、更新或删除重定向时,它将清除缓存。
- 正则表达式支持,您可以在重定向中使用正则表达式。
安装
您可以通过 composer 安装此包
composer require the-3labs-team/nova-redirector-seo
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --tag="nova-redirector-seo-migrations"
php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="nova-redirector-seo-config"
这是发布配置文件的内容
return [ 'cache' => [ 'ttl' => 60 * 60 * 24 * 7, // 7 days ], ];
它将使用您在 config/cache.php
文件中配置的默认缓存驱动程序。
如果您想禁用缓存,可以将 ttl
设置为 null
。
使用方法
现在是时候配置该包了。
Nova 资源
首先,在您的 /app/Providers/NovaServiceProvider.php
中注册 NovaRedirectorSeo
工具(您可能需要添加整个函数)
/** * Register the application's Nova resources. * * @return void */ protected function resources() { Nova::resourcesIn(app_path('Nova')); Nova::resources([ \The3LabsTeam\NovaRedirectorSeo\App\Nova\NovaRedirectorSeo::class, ]); }
现在您可以在 Nova 控板中的 "SEO" 菜单下访问此工具。
中间件
NovaRedirectorSeo 提供了一个中间件,如果当前 URL 不是正确的 URL,则会将用户重定向到正确的 URL。
您可以将此中间件添加到您的 app/Http/Kernel.php
文件中
protected $middleware = [ \The3LabsTeam\NovaRedirectorSeo\App\Http\Middleware\NovaRedirectorSeoMiddleware::class, //...
策略
您可以为 NovaRedirectorSeo 资源添加策略,以限制对资源的访问。
首先,您需要为 NovaRedirectorSeo 资源创建一个策略
php artisan make:policy NovaRedirectorSeoPolicy
然后,在您的 app/Providers/AuthServiceProvider.php
文件中注册策略
protected $policies = [ 'The3LabsTeam\NovaRedirectorSeo\App\Models\NovaRedirectorSeo' => 'App\Policies\NovaRedirectorSeoPolicy', ];
如果您需要,可以使用此策略作为模板
<?php namespace App\Policies; use App\Models\User; use The3LabsTeam\NovaRedirectorSeo\App\Models\NovaRedirectorSeo; use Illuminate\Auth\Access\HandlesAuthorization; class NovaRedirectorSeoPolicy { use HandlesAuthorization; /** * Determine whether the user can view any models. * * @param \App\Models\User $user * @return \Illuminate\Auth\Access\Response|bool */ public function viewAny(User $user) { return true; } /** * Determine whether the user can view the model. * * @param \App\Models\User $user * @param The3LabsTeam\NovaRedirectorSeo\App\Models\NovaRedirectorSeo $novaRedirectorSeo * @return \Illuminate\Auth\Access\Response|bool */ public function view(User $user, NovaRedirectorSeo $novaRedirectorSeo) { return true; } /** * Determine whether the user can create models. * * @param \App\Models\User $user * @param The3LabsTeam\NovaRedirectorSeo\App\Models\NovaRedirectorSeo $novaRedirectorSeo * @return \Illuminate\Auth\Access\Response|bool */ public function create(User $user) { return false; } /** * Determine whether the user can update the model. * * @param \App\Models\User $user * @param The3LabsTeam\NovaRedirectorSeo\App\Models\NovaRedirectorSeo $novaRedirectorSeo * @return \Illuminate\Auth\Access\Response|bool */ public function update(User $user, NovaRedirectorSeo $novaRedirectorSeo) { return false; } /** * Determine whether the user can delete the model. * * @param \App\Models\User $user * @param The3LabsTeam\NovaRedirectorSeo\App\Models\NovaRedirectorSeo $novaRedirectorSeo * @return \Illuminate\Auth\Access\Response|bool */ public function delete(User $user, NovaRedirectorSeo $novaRedirectorSeo) { return false; } /** * Determine whether the user can restore the model. * * @param \App\Models\User $user * @param The3LabsTeam\NovaRedirectorSeo\App\Models\NovaRedirectorSeo $novaRedirectorSeo * @return \Illuminate\Auth\Access\Response|bool */ public function restore(User $user, NovaRedirectorSeo $novaRedirectorSeo) { return false; } /** * Determine whether the user can permanently delete the model. * * @param \App\Models\User $user * @param The3LabsTeam\NovaRedirectorSeo\App\Models\NovaRedirectorSeo $novaRedirectorSeo * @return \Illuminate\Auth\Access\Response|bool */ public function forceDelete(User $user, NovaRedirectorSeo $novaRedirectorSeo) { return false; } }
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全漏洞
请参阅 我们的安全策略 了解如何报告安全漏洞。
鸣谢
许可证
MIT 许可证(MIT)。请参阅 许可证文件 了解更多信息。