shevaua/laravel-seo

此包最新版本(v1.1.1)没有提供许可信息。

用于Laravel Blade模板的SEO工具

v1.1.1 2019-03-01 21:25 UTC

This package is auto-updated.

Last update: 2024-09-29 05:42:13 UTC


README

安装

composer require shevaua/laravel-seo

添加到布局

<head>
    @seo
    ...
    <!-- other tags here -->
</head>

使用外观(Facade)设置SEO信息

<?php

namespace App\Http\Controllers;

use SeoPage;

class TestSeoController extends Controller
{
    
    public function getTestSeoPage()
    {

        $title = 'Hello world!';
        $description = 'This is the test page';

        SeoPage::getInstance()
            ->setTitle($title);

        SeoPage::getInstance()
            ->setMeta('description', $description)
            ->setMeta('author', 'Igor Sheviakov')

            ->setOg('title', $title)
            ->setOg('description', $description);

        return view('test.seopage');

    }

}

使用注入对象设置SEO信息

<?php

namespace App\Http\Controllers;

use Shevaua\LaravelSeo\SeoPage;

class TestSeoController extends Controller
{
    
    public function getTestSeoPage(SeoPage $page)
    {

        $title = 'Hello world!';
        $description = 'This is the test page';

        $page
            ->setTitle($title);

        $page
            ->setMeta('description', $description)
            ->setMeta('author', 'Igor Sheviakov')

            ->setOg('title', $title)
            ->setOg('description', $description);

        return view('test.seopage');

    }

}

参考

使用外观(Facade)

SeoPage::getInstance() - 获取包含SEO信息的单例方法的函数

使用实例

SeoPage->setTitle(string $title) - 设置标题

SeoPage->setMeta(string $name, string $content) - 设置元信息

SeoPage->setOg(string $property, string $content) - 设置带有og前缀的元信息