siberfx/lara-meta 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

siberfx/lara-meta

最新稳定版本:7.1.0

Composer 安装命令:

composer require siberfx/lara-meta

包简介

A package to manage Header Meta Tags for Laravel 10+

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

With this package you can manage header Meta Tags from Laravel controllers.

Installation

From the command line run

$ composer require siberfx/lara-meta

Meta Tags also ships with a facade which provides the static syntax for creating collections. You can register the facade in the aliases key of your config/app.php file if its Laravel 10.x.

'aliases' => [
    // ...
    'MetaTag'   => Siberfx\LaraMeta\Facades\MetaTag::class,

]

Publish the configurations

Run this on the command line from the root of your project:

$ php artisan vendor:publish --provider="Siberfx\LaraMeta\MetaTagsServiceProvider"

A configuration file will be publish to config/meta-tags.php.

Twitter Cards and OpenGraph

Various settings for these options can be found in the config/meta-tags.php file.

Twitter Cards

{!! MetaTag::twitterCard() !!}

OpenGraph

{!! MetaTag::openGraph() !!}

Examples

app/Http/Controllers/Controller.php

<?php 

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

use MetaTag;

abstract class Controller extends BaseController 
{
    use DispatchesCommands, ValidatesRequests;

    public function __construct()
    {
        // Defaults
        MetaTag::set('description', 'description of the page or content you desire to be visible on google searches');
        MetaTag::set('image', asset('images/default-share-image.png'));
    }
}

app/Http/Controllers/HomeController.php

<?php 

namespace App\Http\Controllers;

use MetaTag;

class HomeController extends Controller 
{
    public function index()
    {
        // Section description
        MetaTag::set('title', 'You are at home');
        MetaTag::set('description', 'This is my home. Enjoy!');
        MetaTag::set('keywords', 'This is my home. Enjoy!');
        MetaTag::set('image', asset('images/detail-logo.png'));
        MetaTag::set('canonical', 'http://example.com');

        MetaTag::set('robots', 'index,follow');

   return view('index');
    }

    public function detail()
    {
        // Section description
        MetaTag::set('title', 'This is a detail page');
        MetaTag::set('description', 'All about this detail page');
        MetaTag::set('image', asset('images/detail-logo.png'));

        return view('detail');
    }

    public function private()
    {
        // Section description
        MetaTag::set('title', 'Private Area');
        MetaTag::set('description', 'You shall not pass!');
        MetaTag::set('image', asset('images/locked-logo.png'));

        return view('private');
    }
}

resources/views/layouts/app.blade.php

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="content-type" content="text/html; charset=utf-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <title>{{ MetaTag::get('title') . ' :: '. config('app.name')  }}</title>

        {!! MetaTag::tag('description') !!}
        {!! MetaTag::tag('keywords') !!}
        {!! MetaTag::tag('image') !!}
        {!! MetaTag::tag('image') !!}
        {!! MetaTag::tag('canonical') !!}
        {!! MetaTag::tag('robots') !!}
        
        {!! MetaTag::openGraph() !!}
        
        {!! MetaTag::twitterCard() !!}

        {{--Set default share picture after custom section pictures--}}
        {!! MetaTag::tag('image', asset('images/default-logo.png')) !!}
    </head>

    <body>
        @yield('content')
    </body>
</html>

统计信息

  • 总下载量: 1.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固