Skip to content

Instantly share code, notes, and snippets.

@trizz
Created May 6, 2015 06:55
Show Gist options
  • Save trizz/aff0269a7b93d7fffdb0 to your computer and use it in GitHub Desktop.
Save trizz/aff0269a7b93d7fffdb0 to your computer and use it in GitHub Desktop.
Show a different Blade template based on permission. If 'private' then look for a template in the 'private' folder inside the original folder with the same name.
app('view')->creator('*', function (\Illuminate\Contracts\View\View $view) {
if(env('API_CLIENT_ID') === 'private') {
$viewValues = explode('/', $view->getPath());
$alreadyPrivate = ($viewValues[count($viewValues) - 2] === 'private');
$last = array_pop($viewValues);
array_push($viewValues, 'private', $last);
$privateView = implode('/', $viewValues);
if (file_exists($privateView) && $alreadyPrivate === false) {
$view->setPath($privateView);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment