Skip to content

Commit 876e6ff

Browse files
committed
better config
1 parent e1fb86c commit 876e6ff

File tree

2 files changed

+104
-13
lines changed

2 files changed

+104
-13
lines changed

README.md

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/elegantengineeringtech/laravel-seo/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/elegantengineeringtech/laravel-seo/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/elegantly/laravel-seo.svg?style=flat-square)](https://packagist.org/packages/elegantly/laravel-seo)
77

8-
This package offers an extremly flexible and advanced way to manage all of your seo tags. Unlike other packages that focus on the most simple and common tags, this one implement all the protocols.
8+
This package offers an extremely flexible and advanced way to manage all of your SEO tags. Unlike other packages that focus on the most basic and common tags, this one implements all the protocols.
99

10-
With this package you will be able to implement:
10+
With this package, you will be able to implement:
1111

12-
- The Standard HTML tags (title, robots, ...)
13-
- [The Open Graph tags](https://ogp.me/), including structured properties, arrays and Object Types.
12+
- The standard HTML tags (title, robots, ...)
13+
- [Localization](https://developers.google.com/search/docs/specialty/international/localized-versions) with alternate tags
14+
- [The Open Graph tags](https://ogp.me/), including structured properties, arrays, and Object Types
1415
- [The Twitter tags](https://developer.x.com/en/docs/x-for-websites/cards/overview/abouts-cards)
1516
- [Structured data (JSON-LD)](https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data)
1617

1718
## Installation
1819

19-
You can install the package via composer:
20+
You can install the package via Composer:
2021

2122
```bash
2223
composer require elegantly/laravel-seo
@@ -28,24 +29,102 @@ You can publish the config file with:
2829
php artisan vendor:publish --tag="laravel-seo-config"
2930
```
3031

31-
This is the contents of the published config file:
32+
This is the content of the published config file:
3233

3334
```php
3435
return [
3536
];
3637
```
3738

38-
Optionally, you can publish the views using
39+
## Usage
3940

40-
```bash
41-
php artisan vendor:publish --tag="laravel-seo-views"
41+
You can display all the SEO tags in your view simply by calling the `seo` function like this:
42+
43+
```php
44+
<head>
45+
{!! seo() !!}
46+
</head>
4247
```
4348

44-
## Usage
49+
This function accepts different kinds of arguments, allowing you to take full control over your SEO.
50+
51+
### Basic SEO
52+
53+
The simplest way to define your SEO tags is with `Elegantly\Seo\SeoData::class`.
54+
This class provides a unified representation of the most common SEO tags (Open Graph, Twitter, etc.).
55+
It will also use the defaults defined in your config.
56+
57+
#### From a Controller
58+
59+
Define a `SeoData` object and pass it to the view:
60+
61+
```php
62+
namespace App\Http\Controllers;
63+
64+
use Elegantly\Seo\SeoData;
65+
66+
class HomeController extends Controller
67+
{
68+
function __invoke()
69+
{
70+
return view('home', [
71+
'seo' => new SeoData(
72+
title: "Homepage",
73+
)
74+
]);
75+
}
76+
}
77+
```
78+
79+
Then, in your view, call `seo`:
80+
81+
```php
82+
<head>
83+
{!! seo($seo) !!}
84+
</head>
85+
```
86+
87+
### Advanced SEO
88+
89+
If you need to define your SEO tags in a more precise or complex way, you can use `\Elegantly\Seo\SeoManager::class`.
90+
91+
This class allows you to define every tag individually.
92+
93+
```php
94+
use Elegantly\Seo\SeoManager;
95+
use Elegantly\Seo\SeoTags;
96+
use Elegantly\Seo\Standard\StandardData;
97+
use Elegantly\Seo\OpenGraph\OpenGraph;
98+
use Elegantly\Seo\Twitter\Cards\Card;
99+
use Elegantly\Seo\Schemas\Schema;
100+
101+
$seo = new SeoManager(
102+
standard: new StandardData(
103+
// ...
104+
),
105+
opengraph: new OpenGraph(
106+
// ...
107+
),
108+
twitter: new Card(
109+
// ...
110+
),
111+
schemas: [
112+
new Schema(
113+
// ...
114+
)
115+
],
116+
customTags: new SeoTags(
117+
// ...
118+
),
119+
);
120+
```
121+
122+
Then, just echo it in your view:
45123

46124
```php
47-
$seo = new Elegantly\Seo();
48-
echo $seo->echoPhrase('Hello, Elegantly!');
125+
<head>
126+
{!! seo($seo) !!}
127+
</head>
49128
```
50129

51130
## Testing

src/SeoManager.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
use Elegantly\Seo\Standard\StandardData;
1010
use Elegantly\Seo\Twitter\Cards\Card;
1111
use Elegantly\Seo\Unified\SeoUnifiedData;
12+
use Illuminate\Contracts\Support\Htmlable;
13+
use Stringable;
1214

13-
class SeoManager implements Taggable
15+
class SeoManager implements Htmlable, Stringable, Taggable
1416
{
1517
/**
1618
* @param null|Schema[] $schemas
@@ -70,4 +72,14 @@ public function toTags(): SeoTags
7072

7173
return $tags;
7274
}
75+
76+
public function toHtml(): string
77+
{
78+
return $this->toTags()->toHtml();
79+
}
80+
81+
public function __toString(): string
82+
{
83+
return $this->toHtml();
84+
}
7385
}

0 commit comments

Comments
 (0)