Skip to content

Instantly share code, notes, and snippets.

@Mombuyish
Last active February 17, 2017 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mombuyish/9dda8693b004e0759b4889855692b387 to your computer and use it in GitHub Desktop.
Save Mombuyish/9dda8693b004e0759b4889855692b387 to your computer and use it in GitHub Desktop.
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ComposerServiceProvider extends ServiceProvider
{
/**
* Register bindings in the container.
*
* @return void
*/
public function boot()
{
// Using Closure based composers...
// Here is a simple example...
View::composer('collections.index', function ($view) {
$view->with('posts', Cache::remember('posts', 60 /* cache expired time(mins) */, function() {
return app(\App\Services\PostService::class)->all();
}));
});
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment