Filament Title with Slug 项目教程
1. 项目的目录结构及介绍
filament-title-with-slug/
├── src/
│ ├── FilamentTitleWithSlug.php
│ └── FilamentTitleWithSlugServiceProvider.php
├── config/
│ └── filament-title-with-slug.php
├── resources/
│ └── views/
│ └── filament-title-with-slug.blade.php
├── routes/
│ └── web.php
├── tests/
│ └── Feature/
│ └── FilamentTitleWithSlugTest.php
├── composer.json
├── README.md
└── .gitignore
-
src/: 包含项目的主要源代码文件。
FilamentTitleWithSlug.php
: 主要功能实现文件。FilamentTitleWithSlugServiceProvider.php
: 服务提供者文件,用于注册和引导服务。
-
config/: 包含项目的配置文件。
filament-title-with-slug.php
: 项目的配置文件,定义了各种配置选项。
-
resources/: 包含项目的视图文件。
views/
: 视图文件夹,包含 Blade 模板文件。filament-title-with-slug.blade.php
: 主要的视图文件。
-
routes/: 包含项目的路由文件。
web.php
: 定义了项目的路由。
-
tests/: 包含项目的测试文件。
Feature/
: 功能测试文件夹。FilamentTitleWithSlugTest.php
: 主要的功能测试文件。
-
composer.json: 项目的依赖管理文件。
-
README.md: 项目的说明文档。
-
.gitignore: Git 忽略文件配置。
2. 项目的启动文件介绍
项目的启动文件主要是 src/FilamentTitleWithSlugServiceProvider.php
。这个文件负责注册和引导服务,确保项目在 Laravel 应用中正确加载和运行。
namespace Camya\FilamentTitleWithSlug;
use Illuminate\Support\ServiceProvider;
class FilamentTitleWithSlugServiceProvider extends ServiceProvider
{
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../resources/views', 'filament-title-with-slug');
$this->publishes([
__DIR__.'/../config/filament-title-with-slug.php' => config_path('filament-title-with-slug.php'),
]);
}
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../config/filament-title-with-slug.php', 'filament-title-with-slug'
);
}
}
- boot(): 加载视图文件并发布配置文件。
- register(): 合并配置文件。
3. 项目的配置文件介绍
项目的配置文件位于 config/filament-title-with-slug.php
。这个文件定义了项目的各种配置选项。
return [
'enabled' => env('FILAMENT_TITLE_WITH_SLUG_ENABLED', true),
'slug_separator' => env('FILAMENT_TITLE_WITH_SLUG_SEPARATOR', '-'),
'slug_length' => env('FILAMENT_TITLE_WITH_SLUG_LENGTH', 50),
];
- enabled: 是否启用该功能,默认值为
true
。 - slug_separator: 生成 slug 时使用的分隔符,默认值为
-
。 - slug_length: 生成的 slug 的最大长度,默认值为
50
。
这些配置选项可以通过环境变量进行覆盖,提供了灵活的配置方式。