File tree Expand file tree Collapse file tree 3 files changed +46
-3
lines changed
Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,7 @@ You will typically want to define your SEO tags dynamically in your controllers.
218218namespace App\Http\Controllers;
219219
220220use \Elegantly\Seo\Facades\SeoManager;
221+ use Elegantly\Seo\Standard\Alternate;
221222
222223class HomeController extends Controller
223224{
@@ -226,14 +227,26 @@ class HomeController extends Controller
226227 // Using the helper
227228 seo()
228229 ->setTitle("Homepage")
230+ ->setImage(asset('images/opengraph.jpg'))
229231 ->setDescription("The homepage description")
230- ->when($condition, fn($seo) => $seo->noIndex());
232+ ->when(!App::isProduction(), fn($seo) => $seo->noIndex())
233+ ->setLocale("fr")
234+ ->setAlternates([
235+ new Alternate(
236+ hreflang: "en",
237+ href: route('home', ['locale' => "en"]),
238+ ),
239+ new Alternate(
240+ hreflang: "fr",
241+ href: route('home', ['locale' => "fr"]),
242+ ),
243+ ]);
231244
232245 // Using the facade
233246 SeoManager::current()
234247 ->setTitle("Homepage")
235- ->setDescription("The homepage description")
236- ->when($condition, fn($seo) => $seo->noIndex());
248+ ->setDescription("The homepage description");
249+ // ...
237250
238251 return view('home');
239252 }
Original file line number Diff line number Diff line change 33namespace Elegantly \Seo ;
44
55use Elegantly \Seo \Contracts \Taggable ;
6+ use Elegantly \Seo \OpenGraph \Locale ;
67use Elegantly \Seo \OpenGraph \OpenGraph ;
78use Elegantly \Seo \Schemas \Schema ;
89use Elegantly \Seo \Schemas \WebPage ;
1112use Elegantly \Seo \Twitter \Cards \Card ;
1213use Elegantly \Seo \Twitter \Cards \Summary ;
1314use Illuminate \Contracts \Support \Htmlable ;
15+ use Illuminate \Support \Facades \App ;
1416use Illuminate \Support \Traits \Conditionable ;
1517use Stringable ;
1618
@@ -160,6 +162,22 @@ public function setSitmap(?string $value): static
160162 return $ this ;
161163 }
162164
165+ /**
166+ * @return $this
167+ */
168+ public function setLocale (
169+ string $ value ,
170+ ): static {
171+ if ($ this ->opengraph ) {
172+ $ this ->opengraph ->locale = new Locale (
173+ locale: $ value ,
174+ alternate: $ this ->opengraph ->locale ?->alternate ?? [],
175+ );
176+ }
177+
178+ return $ this ;
179+ }
180+
163181 /**
164182 * @param null|Alternate[] $value
165183 * @return $this
@@ -170,6 +188,13 @@ public function setAlternates(?array $value): static
170188 $ this ->standard ->alternates = $ value ;
171189 }
172190
191+ if ($ this ->opengraph ) {
192+ $ this ->opengraph ->locale = new Locale (
193+ locale: $ this ->opengraph ->locale ?->locale ?? App::getLocale (),
194+ alternate: array_map (fn ($ item ) => $ item ->toOpenGraph (), $ value ?? [])
195+ );
196+ }
197+
173198 return $ this ;
174199 }
175200
Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ public function __construct(
1818 //
1919 }
2020
21+ public function toOpenGraph (): string
22+ {
23+ return $ this ->hreflang ;
24+ }
25+
2126 public function toTags (): SeoTags
2227 {
2328 return new SeoTags ([
You can’t perform that action at this time.
0 commit comments