travelience / seo
此包的最新版本(dev-master)没有可用的许可证信息。
laravel项目的SEO
dev-master
2017-08-19 10:54 UTC
Requires
- php: >=5.6.0
- laravel/framework: ~5.2
This package is auto-updated.
Last update: 2024-09-22 13:39:10 UTC
README
服务提供商
在 config/app.php 中添加服务提供商
Travelience\Seo\SeoServiceProvider::class,
别名
在 config/app.php 中添加 SEO 别名
'SEO' => Travelience\Seo\Facades\Seo::class,`
配置文件
为了编辑此包的默认配置,您可以执行以下操作:
php artisan vendor:publish
路由的翻译文件
如果您支持多语言,您可以使用 lang 文件夹,为每种语言创建一个 seo.php 文件,以自动翻译每种语言的 SEO 元数据。
键是路由名称,例如在 routes/web.php 中:
Route::get('/' , ['as' => 'home', 'uses' => 'Web\HomeController@index']); Route::get('/about' , ['as' => 'about', 'uses' => 'Web\AboutController@index']); Route::get('/company/reviews' , ['as' => 'company.reviews', 'uses' => 'Web\CompanyController@reviews']);
先前路由的翻译文件将是:
<?php return [ 'home' => [ 'title' => 'Home', 'description' => '', 'keywords' => '', ], 'about' => [ 'title' => 'About' ], 'company_reviews' => [ 'title' => 'Company Reviews' ], ];
翻译变量
设置要在翻译中自动替换的变量。
<?php namespace App\Http\Controllers\Web; use App\Http\Controllers\Controller; use Travelience\Seo\Seo; class HomeController extends Controller { public function index() { SEO::set('product', 'Product Name'); return view('home'); } }
MetaTags
默认的元数据在 config/seo.php 文件中,但如果您需要向特定页面添加一个元数据,请使用以下方法:
SEO::meta('name', 'value');
MicroFormats
如果您需要设置一个微格式,请查看此示例
SEO::microformat('TouristAttraction', [ 'name' => 'Asakusa', 'description' => ':description', 'aggregateRating' => [ '@type' => 'AggregateRating', 'ratingValue' => '5.0' ] ]);