Skip to content

Instantly share code, notes, and snippets.



Last active Jan 11, 2017
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
$page = $_SERVER['REQUEST_URI'];
$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