Skip to content

Commit 536316a

Browse files
committed
Add publish command, fix flushing of pivot releationships, fix detection if cache is disabled
1 parent 949697b commit 536316a

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

Diff for: CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.6.2] - 2019-07-26
8+
### Added
9+
- 'modelCache:publish' artisan command.
10+
- Spatie's QueryBuilder package to list of incompatible packages.
11+
12+
### Fixed
13+
- registration of config file in service provider.
14+
- detection if cache is disabled.
15+
- flushing of cache for pivot events.
16+
717
## [0.6.1] - 2019-07-20
818
### Added
919
- config and environment variable to allow removal of database information from cache-key.

Diff for: src/Console/Commands/Publish.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php namespace GeneaLabs\LaravelModelCaching\Console\Commands;
2+
3+
use GeneaLabs\LaravelModelCaching\Providers\Service;
4+
use Illuminate\Console\Command;
5+
6+
class Publish extends Command
7+
{
8+
protected $signature = 'modelCache:publish {--assets} {--config} {--views} {--migrations}';
9+
protected $description = "Publish various assets of the 'Model Caching for Laravel' package.";
10+
11+
public function handle()
12+
{
13+
if ($this->option('assets')) {
14+
$this->call('casts:publish', ['--assets' => true]);
15+
}
16+
17+
if ($this->option('config')) {
18+
$this->call('vendor:publish', [
19+
'--provider' => Service::class,
20+
'--tag' => ['config'],
21+
'--force' => true,
22+
]);
23+
}
24+
25+
if ($this->option('views')) {
26+
$this->call('vendor:publish', [
27+
'--provider' => Service::class,
28+
'--tag' => ['views'],
29+
'--force' => true,
30+
]);
31+
}
32+
33+
if ($this->option('migrations')) {
34+
$this->call('vendor:publish', [
35+
'--provider' => Service::class,
36+
'--tag' => ['migrations'],
37+
'--force' => true,
38+
]);
39+
}
40+
}
41+
}

Diff for: src/Providers/Service.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Providers;
22

33
use GeneaLabs\LaravelModelCaching\Console\Commands\Clear;
4+
use GeneaLabs\LaravelModelCaching\Console\Commands\Publish;
45
use GeneaLabs\LaravelModelCaching\Helper;
56
use Illuminate\Support\ServiceProvider;
67

@@ -12,7 +13,13 @@ public function boot()
1213
{
1314
$configPath = __DIR__ . '/../../config/laravel-model-caching.php';
1415
$this->mergeConfigFrom($configPath, 'laravel-model-caching');
15-
$this->commands(Clear::class);
16+
$this->commands([
17+
Clear::class,
18+
Publish::class,
19+
]);
20+
$this->publishes([
21+
$configPath => config_path('laravel-model-caching.php'),
22+
], "config");
1623
}
1724

1825
public function register()

Diff for: src/Traits/Caching.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ protected function checkCooldownAndFlushAfterPersisting(Model $instance, string
249249
if ($relationship) {
250250
$relationshipInstance = $instance->$relationship()->getModel();
251251

252-
if (method_exists($instance, "flushCache")) {
252+
if (method_exists($relationshipInstance, "flushCache")) {
253253
$relationshipInstance->flushCache();
254254
}
255255
}

Diff for: src/Traits/ModelCaching.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public function __set($key, $value)
4040

4141
public static function all($columns = ['*'])
4242
{
43-
$isCacheDisabled = Container::getInstance()
43+
$cacheIsEnabled = Container::getInstance()
4444
->make("config")
45-
->get("laravel-model-caching.disabled");
45+
->get("laravel-model-caching.enabled");
4646

47-
if ($isCacheDisabled) {
47+
if (! $cacheIsEnabled) {
4848
return parent::all($columns);
4949
}
5050

0 commit comments

Comments
 (0)