Reputation: 379
i want to check if laravel cache tag exist. how can i do that.
this is how to get cache item but how can you validate if a cache tag exist.
$john = Cache::tags(['people', 'artists'])->get('John');
$anne = Cache::tags(['people', 'authors'])->get('Anne');
Upvotes: 1
Views: 4762
Reputation: 154
i know its an older question but you can simply do:
Cache::tags(['people', 'artists'])->has('John');
this will check if a key of John exists in tags people or artists.
Upvotes: 4
Reputation:
If $john is false, null or '' it won't pass the if statement
if ($john) {
// It has valid data
}
or you can check for an empty object/collection using:
$john->isEmpty();
also u can check with count() method using :
if ($jhon->count()) {
// do something
}
Upvotes: 0