Skip to content

Instantly share code, notes, and snippets.

@escuccim
Last active January 11, 2017 11:20
Show Gist options
  • Save escuccim/5316a553a085eca6e8b9ce8119a73837 to your computer and use it in GitHub Desktop.
Save escuccim/5316a553a085eca6e8b9ce8119a73837 to your computer and use it in GitHub Desktop.
Laravel helper function to get translated page title and description from lang file metadata.php
function getMetaData($type){
// set a default so it doesn't break phpunit
if(isset($_SERVER['REQUEST_URI']))
$page = $_SERVER['REQUEST_URI'];
else
$page = "/";
// if we are looking at a blog article just use the default for the main blog page
if(strpos($page, 'blog') !== false) {
$page = '/blog';
}
// get the data from the lang files
$data = trans('metadata.' . $page . '-' . $type);
// if the key doesn't exist use the default
if($data == 'metadata.' . $page . '-' . $type) {
$data = trans('metadata.default-' . $type);
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment