am2studio/laravel-seo-meta
Composer 安装命令:
composer require am2studio/laravel-seo-meta
包简介
Laravel seo meta
README 文档
README
Package for handling seo meta tags in Laravel apps
Install
Via Composer
$ composer require am2studio/laravel-seo-meta
Usage
First run migration for this package (src/migration/):
Schema::create('seo_metas', function (Blueprint $table) { $table->increments('id'); $table->string('model_type'); $table->integer('model_id')->unsigned(); $table->text('key'); $table->text('value'); $table->timestamps(); });
For each model which that use seo meta add trait "SeoMetaTrait" and implement interface "SeoMetaInterface"
use AM2Studio\Laravel\SeoMeta\SeoMetaTrait; use AM2Studio\Laravel\SeoMeta\SeoMetaInterface; class User implements SeoMetaInterface { use SeoMetaTrait;
Interface "SeoMetaInterface" have 2 function that model need to implement "seoMetasConfig()" and "seoMetas()"
seoMetasConfig() is configuration for meta data for model
seoMetas() is "hasMany" relation to seoMetas of model
public function seoMetasConfig() { return [ 'title' => ['generator' => 'example.com - '. $this->title], 'description' => ['generator' => 'green-rush.com - '. $this->title . ' - ' . $this->short_description,], 'keywords' => ['generator' => 'greenrush, product, ' . $this->title . ', ' . $this->short_description, 'edit'=> false], 'og:image' => ['generator' => ["http://i.stack.imgur.com/hEobN.jpg", "http://i.stack.imgur.com/hEobN2.jpg"]], 'twitter:site' => [], ]; } public function seoMetas() { return $this->hasMany(SeoMeta::class, 'model_id')->where(['model_type' => __CLASS__]); }
Each seo meta that you want model to use must be fefined here. List of possible seo meta tags:
title -> string description -> string keywords -> string canonical -> string article:published_time -> string article:section -> string og:description -> string og:title -> string og:url -> string og:type -> string og:locale -> string og:locale:alternate -> array og:site_name -> string og:image -> array og:image:url -> array og:image:size -> string twitter:card -> string twitter:title -> string twitter:site -> string
For each seo meta in config you define generator(how seo meta will be generated) and edit (if seo meta can be edited or will be always generated on model save, default - true)
Finaly add "seoMeta" to Model -> fillable
protected $fillable = [ ... 'seoMeta' ];
Show form for meta seo deta on model:
{!! \AM2Studio\Laravel\SeoMeta\SeoMetaHelper::form($product) !!}
Set data in controller:
public function __construct() { parent::__construct(); SeoMetaHelper::setSeoMeta(['title' => 'Default title __construct .']); } public function index() { SeoMetaHelper::setSeoMeta(['description' => 'Default description index .']); return $this->view('index'); } public function show($product) { SeoMetaHelper::setSeoMeta($product->getSeoMeta()); return $this->view('show', compact('product')); }
Show meta in view :
{{
\AM2Studio\Laravel\SeoMeta\SeoMetaHelper::render([
//alternative data if is not set anywhere
'keywords' => 'example.com -> frontend layout'
])
}}
Change log
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING and CONDUCT for details.
License
The MIT License (MIT). Please see License File for more information.
am2studio/laravel-seo-meta 适用场景与选型建议
am2studio/laravel-seo-meta 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.33k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「AM2Studio」 「Laravel seo meta」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 am2studio/laravel-seo-meta 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 am2studio/laravel-seo-meta 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 am2studio/laravel-seo-meta 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Help to manage meta data on Laravel Eloquent model
Service provider for finite
Admin form helper
Laravel table sorter
Laravel exporter
Statamic Fine Seo addon
统计信息
- 总下载量: 6.33k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-22