jegex/laravel-seo
Composer 安装命令:
composer require jegex/laravel-seo
包简介
This is my package laravel-seo
关键字:
README 文档
README
A comprehensive SEO package for Laravel inspired by Rank Math SEO (WordPress). Features include meta tags, Open Graph, Twitter Cards, template variables, sitemap generation, redirect management, and 404 tracking.
Note: This is a core SEO package - no admin dashboard included. For a Filament admin dashboard, check out the separate
filament-seopackage.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require jegex/laravel-seo
You can publish and run the migrations with:
php artisan vendor:publish --tag="laravel-seo-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="laravel-seo-config"
Optionally, you can publish the views using
php artisan vendor:publish --tag="laravel-seo-views"
Quick Start
1. Add Trait to Your Model
use Jegex\LaravelSeo\Traits\HasSeo; class Post extends Model { use HasSeo; }
2. Use in Your Blade Layout
<!DOCTYPE html> <html> <head> {{ seo()->render() }} </head> <body> @yield('content') </body> </html>
3. Configure Templates (config/seo.php)
return [ 'site_name' => 'My Blog', 'site_description' => 'A blog about Laravel', 'separator' => ' - ', 'templates' => [ 'post' => [ 'title' => '%title% %sep% %sitename%', 'description' => '%excerpt%', ], ], 'webmaster_verification' => [ 'google' => 'your-google-verification-code', 'bing' => 'your-bing-verification-code', ], ];
Features
Template Variables (Rank Math Style)
Use these variables in your templates:
| Variable | Description |
|---|---|
%title% |
Model title |
%sitename% |
Website name |
%sitedesc% |
Website description |
%sep% |
Separator (default: -) |
%currentdate% |
Current date |
%currentyear% |
Current year |
%author% |
Author name |
%excerpt% |
Content excerpt (160 chars) |
%categories% |
Categories list |
%tags% |
Tags list |
Helper Functions
// Set SEO data seo('title', 'My Page Title'); seo('description', 'Page description'); seo('og:image', '/path/to/image.jpg'); // Or use methods seo()->setTitle('My Title')->setDescription('My Description'); // Parse templates manually parse_seo_template('%title% %sep% %sitename%', ['title' => 'Hello']);
Blade Components
<x-seo::meta-tags /> <x-seo::json-ld :schema="['@type' => 'Article', 'headline' => $title]" /> <x-seo::breadcrumbs :items="[['name' => 'Home', 'url' => '/'], ['name' => $category]]" />
Webmaster Verification
Add verification codes in config/seo.php:
'webmaster_verification' => [ 'google' => 'abc123...', 'bing' => 'xyz789...', 'pinterest' => 'pinterest-code', 'yandex' => 'yandex-code', ],
Redirect Management
use Jegex\LaravelSeo\Models\Redirect; // Create a 301 redirect Redirect::create([ 'from_url' => '/old-page', 'to_url' => '/new-page', 'type' => 301, ]); // Create a regex redirect Redirect::create([ 'from_url' => '#/blog/(.*)#', 'to_url' => '/articles/$1', 'type' => 301, 'is_regex' => true, ]); // 410 Gone Redirect::create([ 'from_url' => '/deleted-page', 'type' => 410, ]);
Middleware
Add to your app/Http/Kernel.php:
protected $middleware = [ // ... \Jegex\LaravelSeo\Http\Middleware\RedirectMiddleware::class, \Jegex\LaravelSeo\Http\Middleware\NotFoundTrackerMiddleware::class, ];
SEO Analysis
CLI Command
# Analyze all SEO entries php artisan seo:analyze # Analyze specific model php artisan seo:analyze --model="App\Models\Post" # Calculate and save scores php artisan seo:analyze --calculate-scores
Model Analysis
$entry = $post->seoEntry; // Get full analysis $analysis = $entry->analyze(); // [ // 'score' => 85, // 'alerts' => ['Title is slightly long...'], // 'checks' => [...], // 'details' => [...] // ] // Get score only $entry->calculateScore(); echo $entry->seo_score; // 85 // Get score label echo $entry->getScoreLabel(); // 'Good', 'Needs Improvement', or 'Poor'
Programmatic Analysis
use Jegex\LaravelSeo\Services\AnalyzerService; $analyzer = app(AnalyzerService::class); $analysis = $analyzer->analyze($content, [ 'title' => 'My Title', 'description' => 'My Description', 'focus_keyword' => 'laravel seo', ]); echo $analysis['score']; // 0-100 echo $analysis['alerts'][0]; // First alert message
Breadcrumbs
Via Service
// Manual breadcrumbs seo()->breadcrumbs() ->add('Home', '/') ->add('Blog', '/blog') ->add($post->title, $post->url()); // Auto from route seo()->breadcrumbs()->fromRoute(); // Render {{ seo()->breadcrumbs()->renderHtml() }} {{ seo()->breadcrumbs()->renderSchema() }}
Via Blade Component
<x-seo::breadcrumbs :items="[ ['name' => 'Home', 'url' => '/'], ['name' => 'Blog', 'url' => '/blog'], ['name' => $post->title] ]" />
JSON-LD Structured Data
Available Schema Types
article- Article/BlogPostingwebsite- WebSite with SearchActionorganization- Organization with contact infobreadcrumbs- BreadcrumbList
Creating Schema
// Via SEO service (auto-rendered) seo()->addSchema('article') ->headline('My Article') ->author('John Doe') ->datePublished(now()->toIso8601String()) ->image('https://example.com/image.jpg'); // Via Schema service seo()->schema() ->website() ->name('My Site') ->url('/') ->potentialActionSearch('/search?q={search_term_string}'); // Organization schema seo()->schema() ->organization() ->name('My Company') ->url('https://example.com') ->contactPoint('+1-234-567-8900', 'customer service');
Rendering
{{-- In your layout, schemas auto-render with meta tags --}} {{ seo()->render() }} {{-- Or render schemas only --}} {{ seo()->schema()->render() }} {{-- Manual schema --}} <x-seo::json-ld :schema="['@type' => 'Article', 'headline' => $title]" />
Complete Example
Controller
class PostController extends Controller { public function show(Post $post) { // Automatically uses HasSeo trait for defaults seo()->for($post); // Or manually override seo()->setTitle($post->title . ' | Custom Suffix'); return view('posts.show', compact('post')); } }
View (posts/show.blade.php)
@extends('layouts.app') @section('content') <article> <h1>{{ $post->title }}</h1> <div>{{ $post->content }}</div> </article> @endsection
Layout (layouts/app.blade.php)
<!DOCTYPE html> <html lang="{{ app()->getLocale() }}"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> {{-- Render all SEO meta tags --}} {{ seo()->render() }} @stack('styles') </head> <body> @yield('content') @stack('scripts') </body> </html>
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
jegex/laravel-seo 适用场景与选型建议
jegex/laravel-seo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-seo」 「jegex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jegex/laravel-seo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jegex/laravel-seo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jegex/laravel-seo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Manage SEO tags within your Laravel application
This package will help you to manage your website SEO easily.
An Elegant & flexible SEO tag builder for Laravel
Analyze keywords in the content and make diagnostics to improve the seo score of the content.
A complete SEO package for Laravel, covering everything from meta tags to social sharing and structured data.
Laravel SEO package
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 45
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-29