Skip to content

Instantly share code, notes, and snippets.

@escuccim escuccim/helpers.php
Last active Jan 11, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.