Created
June 2, 2016 13:27
-
-
Save tommymarshall/f875c5e2cffac20a66184f259612f306 to your computer and use it in GitHub Desktop.
Feed meta data values into a view only once based on a route (right now, every time a view is called it gets overwritten) ie. Want to reference in my layouts.base {{ meta.title }}.
This file contains 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\Providers; | |
use Illuminate\Support\ServiceProvider; | |
class MetaViewServiceProvider extends ServiceProvider | |
{ | |
public function boot() | |
{ | |
view()->composer('*', function ($view) { | |
$view_name = $view->getName(); | |
$meta = trans('meta.default'); | |
if (array_key_exists($view_name, trans('meta'))) | |
{ | |
$meta = trans('meta')[$view_name]; | |
} | |
return $view->with(compact('meta')); | |
}); | |
} | |
// required method to satisfy abstract class method signature | |
public function register() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment