GithubHelp home page GithubHelp logo

nacer-ben / laravel-seo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from romanzipp/laravel-seo

0.0 0.0 0.0 312 KB

SEO package made for maximum customization and flexibility

Home Page: https://packagist.org/packages/romanzipp/laravel-seo

License: MIT License

PHP 100.00%

laravel-seo's Introduction

Laravel SEO

Latest Stable Version Total Downloads License GitHub Build Status

A SEO package made for maximum customization and flexibility.

Contents

Installation

composer require romanzipp/laravel-seo

Configuration

Copy configuration to config folder:

$ php artisan vendor:publish --provider="romanzipp\Seo\Providers\SeoServiceProvider"

Documentation

Usage

Instantiation

use romanzipp\Seo\Facades\Seo;
use romanzipp\Seo\Services\SeoService;

class IndexController
{
    public function index(Request $request, SeoService $seo)
    {
        $seo = seo();

        $seo = app(SeoService::class);

        $seo = Seo::make();
    }
}

Render

{{ seo()->render() }}

Examples

This package offers many ways of adding new elements (Structs) to your <head>.

  1. Add commonly used structs via shorthand setters like seo()->title('...'), seo()->meta('...')
  2. Manually add single structs via the seo()->add() methods
  3. Specify an array of contents via seo()->addFromArray()

Take a look at the structs documentation or example app for more detailed usage.

Title

seo()->title('Laravel');
<title>Laravel</title>
<meta property="og:title" content="Laravel" />
<meta name="twitter:title" content="Laravel" />

Description

seo()->description('Catchy marketing headline');
<meta name="description" content="Catchy marketing headline" />
<meta property="og:description" content="Catchy marketing headline" />
<meta name="twitter:description" content="Catchy marketing headline" />

CSRF Token

seo()->csrfToken();
<meta name="csrf-token" content="a7588c617ea5d8833374d8eb3752bcc4071" />

Charset & Viewport

seo()->charset();
seo()->viewport();
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

Twitter

seo()->twitter('card', 'summary');
seo()->twitter('creator', '@romanzipp');
<meta name="twitter:card" content="summary" />
<meta name="twitter:creator" content="@romanzipp" />

Open Graph

seo()->og('site_name', 'Laravel');
seo()->og('locale', 'de_DE');
<meta name="og:site_name" content="Laravel" />
<meta name="og:locale" content="de_DE" />

Meta

seo()->meta('copyright', 'Roman Zipp');
<meta name="copyright" content="Roman Zipp" />

For more information see the structs documentation.

Laravel-Mix Integration

You can include your mix-manifest.json file generated by Laravel-Mix to automatically add preload/prefetch link elements to your document head.

Basic example

seo()
    ->mix()
    ->load();

mix-manifest.json

{
  "/js/app.js": "/js/app.js?id=123456789",
  "/css/app.css": "/css/app.css?id=123456789"
}

document <head>

<link rel="prefetch" href="/js/app.js?id=123456789" />
<link rel="prefetch" href="/css/app.css?id=123456789" />

Extended usage

Take a look at the SEO Laravel-Mix integration docs for further usage.

use romanzipp\Seo\Conductors\Types\ManifestAsset;

seo()
    ->mix()
    ->map(static function(ManifestAsset $asset): ?ManifestAsset {

        if (strpos($asset->path, 'admin') !== false) {
            return null;
        }

        $asset->url = "http://localhost/{$asset->url}";

        return $asset;
    })
    ->load(public_path('custom-manifest.json'));

Schema.org Integration

This package features a basic integration for Spaties Schema.org package to generate ld+json scripts. Added Schema types render with the packages structs.

use Spatie\SchemaOrg\Schema;

seo()->addSchema(
    Schema::localBusiness()->name('Spatie')
);
use Spatie\SchemaOrg\Schema;

seo()->setSchemes([
    Schema::localBusiness()->name('Spatie'),
    Schema::airline()->name('Spatie'),
]);

Take a look at the Schema.org package Docs.

Upgrading

Cheat Sheet

Code Rendered HTML
Shorthand Setters
seo()->title('Laravel') <title>Laravel</title>
seo()->description('Laravel') <meta name="description" content="Laravel" />
seo()->meta('author', 'Roman Zipp') <meta name="author" content="Roman Zipp" />
seo()->twitter('card', 'summary') <meta name="twitter:card" content="summary" />
seo()->og('site_name', 'Laravel') <meta name="og:site_name" content="Laravel" />
seo()->charset() <meta charset="utf-8" />
seo()->viewport() <meta name="viewport" content="width=device-width, ..." />
seo()->csrfToken() <meta name="csrf-token" content="..." />
Adding Structs
seo()->add(...) <meta name="foo" />
seo()->addMany([...]) <meta name="foo" />
seo()->addIf(true, ...) <meta name="foo" />
Various
seo()->mix()
seo()->hook()
seo()->render()

Testing

./vendor/bin/phpunit

laravel-seo's People

Contributors

romanzipp avatar spekulatius avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.