Skip to content

Instantly share code, notes, and snippets.

@wtoalabi
Created May 31, 2019 14:01
Show Gist options
  • Save wtoalabi/50ff0cb790a6d23b45bac493a181ebc7 to your computer and use it in GitHub Desktop.
Save wtoalabi/50ff0cb790a6d23b45bac493a181ebc7 to your computer and use it in GitHub Desktop.
<?php
namespace App\Providers;
use App\CacheDirective;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class CustomCacheServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->singleton(CacheDirective::class);
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
Blade::directive('cache', function ($expression) {
return "<?php if (!App\CacheDirective::setUp($expression)) {?>";
});
Blade::directive('endcache', function () {
return "<?php } echo App\CacheDirective::tearDown() ?>";
});
if ($this->app->isLocal()) {
$cache = app(Repository::class);
$cache->tags('views')->flush();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment