Created
November 18, 2017 11:47
-
-
Save Cannonb4ll/3cb35f181328efab963835ce5b671608 to your computer and use it in GitHub Desktop.
A
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function canonical() | |
{ | |
$route = Route::current(); | |
if (!$route) { | |
return false; | |
} | |
$action = $route->getAction(); | |
if (!$action) { | |
return false; | |
} | |
if (!array_has($action, 'uses') or $action['uses'] instanceof Closure) { | |
return false; | |
} | |
$uses = explode('App\Http\Controllers\\', $action['uses'])[1]; | |
if (!$uses) { | |
return false; | |
} | |
$parameters = $route->parameters(); | |
if ($parameters) { | |
return action($uses, $parameters); | |
} else { | |
return action($uses); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits; | |
trait Shareable | |
{ | |
public function getShareUrl($type = 'facebook') | |
{ | |
if ($type == 'facebook') { | |
$query = urldecode(http_build_query([ | |
'app_id' => env('FACEBOOK_ID'), | |
'href' => canonical(), | |
'display' => 'page', | |
'title' => $this->title | |
])); | |
return 'https://www.facebook.com/dialog/share?' . $query; | |
} | |
if ($type == 'twitter') { | |
$query = urldecode(http_build_query([ | |
'url' => canonical(), | |
'text' => str_limit($this->title, 100) | |
])); | |
return 'https://twitter.com/intent/tweet?' . $query; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment