Created
May 31, 2019 14:01
-
-
Save wtoalabi/50ff0cb790a6d23b45bac493a181ebc7 to your computer and use it in GitHub Desktop.
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 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