artesaos / seotools

SEO Tools for Laravel
MIT License
3.07k stars 503 forks source link

OpenGraph #70

Closed ItsLhoudini closed 7 years ago

ItsLhoudini commented 8 years ago

Hi,

why don't put in defaults value url Url::current() like the canonical one?

jakemitchellxyz commented 8 years ago

I'm currently working on that

ItsLhoudini commented 8 years ago

I have found now a "quick & dirty" solution like this:

public function __construct() { $this->seo()->opengraph()->setUrl(URL::current()); }

inside the "main" Controller.php

jakemitchellxyz commented 8 years ago

If my next pull gets accepted, it'll happen within the getCanonical() method automatically

ItsLhoudini commented 8 years ago

GREAT!

ramon-villain commented 7 years ago

@Lhoudini Lumen doesn't support Facades, so this should be in more agnostic way. @MeestorHok did you figured out?

qerim commented 7 years ago

If anyone is still looking to resolve this:

At the very top of /config/seotools.php:

/**
 * Set og:url
 * Done this way due to ensure no php warnings are encountered when running artisan commands
 * Because 'HTTP_HOST' / 'REQUEST_URI' are available only when using browser
 */
if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) {
    $currentURL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} else {
    $currentURL = null;
}

return [
    'meta'      => [ ...

In that same file at 'opengraph' section:

'defaults' => [
    'title'       => '.........'
    'description' =>  '.........'
    'url'         => $currentURL,