mikebronner / laravel-model-caching Goto Github PK
View Code? Open in Web Editor NEWEloquent model-caching made easy.
License: MIT License
Eloquent model-caching made easy.
License: MIT License
/cc @jurrid
In the test suite there is one folder containing tests tests/Unit
.
These are not unit tests as they interact with an external service integration. Thus they are tests/Integration
tests because they touch either SQLite or MySQL implementation.
Rename tests folders to represent the tests they actually perform.
it seems it would be very useful to be able to turn off caching at a single point.. most caching packages have a true/false config option that can easily be triggered from the .env file
any chance you could add this please?
One part of my application seems to be broken since I started using this package. I've isolated the problem now
I have a table with 300 records
$records = Place::where('place_id', $placeId)->get();
$records->count() is = 1 here
then below I run
$records = Place::where('place_id', '!=', $placeId)->get();
I tried with '<>' but that is the same as '!='
$records->count() should be 299 now, but instead it uses the cache from the above query and returns the same as the above query.. so count is 1.. and instead of getting "Every other record" it is just returning the same record
So it looks like it doesn't differentiate between the two
$start_quarter = '2018-01-01'; $end_quarter = '2018-03-31'; $start_month = '2018-02-01'; $end_month = '2018-02-29';
Query1 ```
$sales['quarter'] = SaleItem::whereBetween('created_at', [$start_quarter, $end_quarter])
->whereIn('shop_id', $shops)
->whereIn('sku', $s_products)
->count();
Query2: ```
$sales['month'] = SaleItem::whereBetween('created_at', [$start_month,$end_month])
->whereIn('shop_id', $shops)
->whereIn('sku', $s_products)
->count();
I receive identical values for both queries...
The queries are fired straight after another and the result is the same in both queries...
Can i provide a custom tag or something? If $shops or $s_products changes the result is fine, but if the one of the dates is different the result is the same...
Error: *`
Laravel Version: 5.5.34
Laravel Model Caching Package Version: 0.2.22
PHP Version: 7.1.14
Undefined index Column
Laravel Version: 5.5.23
Laravel Model Caching Package Version: 0.2.9
PHP Version: 7.0.26
Homestead Version: none
Operating System & Version: name x.y.z
When I use orderByRaw('RAND()') in a model, I get These error. The simple solution is to test if the key exists.
// vendor/genealabs/laravel-model-caching/src/CacheKey.php
protected function getOrderByClauses() : string
{
$orders = collect($this->query->orders);
return $orders->reduce(function($carry, $order){
return $carry . '_orderBy_' . $order['column'] . '_' . $order['direction'];
})
?: '';
}
protected function getOrderByClauses() : string
{
$orders = collect($this->query->orders);
return $orders->reduce(function($carry, $order){
return $carry . '_orderBy_' . (isset($order['column']) ? $order['column'] : '') . '_' . (isset($order['direction']) ? $order['direction'] : '');
})
?: '';
}
*Alle queries with count() or sum('columnXYZ' return a "undefined index, operator" error.
Exapmle: $sale = SaleItem::whereIn('sku', $prod_array) ->whereBetween('created_at', [$start, $end]) ->count();
*
Laravel Version: 5.5.34
Laravel Model Caching Package Version: 0.2.21
PHP Version: 7.1.0
*/home/vagrant/Projects/bvj-portal-55/vendor/genealabs/laravel-model-caching/src/CacheKey.php
return $carry . '_orderBy_' . $order['column'] . '_' . $order['direction'];
})
?: '';
}
protected function getQueryColumns(array $columns) : string
{
if ($columns === ['*'] || $columns === []) {
return '';
}
return '_' . implode('_', $columns);
}
protected function getTypeClause($where) : string
{
$type =in_array($where['type'], ['In', 'Null', 'NotNull'])
? strtolower($where['type'])
: strtolower($where['operator']);
return str_replace(' ', '_', $type);
}
protected function getValuesClause(array $where = null) : string
{
return is_array(array_get($where, 'values'))
? '_' . implode('_', $where['values'])
: '';
}
protected function getWhereClauses(array $wheres = []) : string
{
return $this->getWheres($wheres)
->reduce(function ($carry, $where) {
$value = $this->getNestedClauses($where);
$value .= $this->getColumnClauses($where);
$value .= $this->getRawClauses($where);
$value .= $this->getOtherClauses($where, $carry);
Arguments
"Undefined index: operator (View: /home/vagrant/Projects/bvj-portal-55/resources/views/start.blade.php)"*
Code is already in place, all that is needed is the unit test to back it up.
using different cache driver for model caching other than the app specific cache driver
Laravel Version: 5.5.25
Laravel Model Caching Package Version: 0.2.12
PHP Version: 7.1.11
Operating System & Version: Ubuntu 16.04
It has to be created cache for when tried to retrieve from a model, some result that we doesn't want a relationship attached.
For example: Authors that does not have books:
$authors = collect([(new Author)->doesntHave('books')->first()]);
Currently, if we try to execute the method, we have this stack:
ErrorException: Undefined index: column
/home/vagrant/Code/laravel-model-caching/src/CachedBuilder.php:106
/home/vagrant/Code/laravel-model-caching/vendor/laravel/framework/src/Illuminate/Support/Collection.php:1197
/home/vagrant/Code/laravel-model-caching/src/CachedBuilder.php:107
/home/vagrant/Code/laravel-model-caching/src/CachedBuilder.php:28
/home/vagrant/Code/laravel-model-caching/src/CachedBuilder.php:203
The lib is returning null to attributes of type Polygon (Mysql). The Polygon type is saved in blob format in mysql database, and the lib is saving the blob as null (or as hex, I'm still analyzing) in redis.
Laravel Version: 5.5
Laravel Model Caching Package Version: 0.2.23
PHP Version: 7.2
Operating System & Version: Ubuntu 16.04
Is there way to store cache not forever? As i see in code, everything is using rememberForever
method.
Thank you!
When working through some issues, I discovered that redis caching may not be working properly in some cases. I am working on debugging this. There seems to be an issue with cursor
queries.
Implement hash collision prevention mechanism:
Some users have installations that do not use sessions as they have stateless APIs that authenticate with JWT tokens (Laravel Passport). This architecture is common and popular as it adheres to the 12 factor app principals of stateless server apps.
We therefore disable session service providers and facades as there is a significant performance increase in doing so. Along with other services.
Laravel Version: 5.5.x
Laravel Model Caching Package Version: latest
PHP Version: 7.2.x
Homestead Version: N/A - Docker (docker makes homestead development look like 1965)
Operating System & Version: Alpine Linux 3.5
26) Tests\Integration\Services\JobWorkflow\WorkflowDraftToPendingTest::it_throws_exception_on_insufficient_credits
Failed asserting that exception of type "ReflectionException" matches expected exception "App\Exceptions\InsufficientCredits". Message was: "Class session does not exist" at
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:752
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:631
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:586
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:732
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:110
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:839
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/genealabs/laravel-model-caching/src/CachedModel.php:20
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:873
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:169
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Support/Collection.php:339
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:173
/drone/src/bitbucket.org/ethical-jobs/api-app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:153
/drone/src/bitbucket.org/ethical-jobs/api-app/tests/TestFactories/OrganisationFactory.php:37
/drone/src/bitbucket.org/ethical-jobs/api-app/tests/Integration/Services/JobWorkflow/WorkflowDraftToPendingTest.php:188
In your class GeneaLabs\LaravelModelCaching\CachedModel
you have a method newEloquentBuilder()
that creates the builder instance. You are using a session based store to retain state regarding enabled / disabled status of the package.
As your package is based around caching one can expect a caching engine to be a requirement, the docs even suggest Redis as a best fit - with this I agree.
I believe its wrong to alos depend on the session driver for this package as another dependancy when you could simply store this session('genealabs-laravel-model-caching-is-disabled')
key in the cache as well. Thus only having one external service dependancy - packages should have as few as possible to remain flexible. Also I cant see why session is being used for this over cache in the first place?
I've run Product::find(1)
and run Product::find(2)
but the result of the query is collection of product 1
the cache doesn't invalidate automatically
In my Product.php:
`
namespace App\Models;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
use SoftDeletes, Cachable;`
Laravel Version: 5.6.3
Laravel Model Caching Package Version: 0.2.33
PHP Version: 7.2.0
Homestead Version: x.y
Operating System & Version: Ubuntu 16.0.4
They cache keys and naming scheme is quite hard for developers to read and does not follow any recognisable pattern e.g. 'genealabslaravelmodelcachingtestsfixturesbook'
It would be more readable and best practice to follow a cache key namespacing architecture as those recommended by Redis.
e.g.
genealabs:model-caching:test-fixtures:book
So I have a query such as this. and i have an api endpoint categories/id/products..
$collection = ProductVariant::with( 'product.owner' )->whereHas( 'product', function( $q ) use ( $categoryId )
{
$q->whereCategoryId($categoryId)->live();
} )->inRandomOrder()->live(1)
but when i change the id to say 2 or 3.. I get same products.. is this something I have to take care of? or am i doing something wrong?
Laravel Version: 5.6.2
Laravel Model Caching Package Version: ^0.2.22
PHP Version: * 7.1.6 *
Homestead Version: N/A (using Valet)
Operating System & Version: *Mac OS - El captain - 10.11.6 *
Laravel 5.5, laravel-model-caching: 0.2.31
If i use caching with my models and there is only one result on calling all()/get() i receive the model, not a collection. This is a different handling to laravel!
Continuation of discussion from #59.
My thoughts on this are the following:
If a model does not contain the protected property, none of the above will take place, and cache invalidation will proceed as normal.
php artisan modelCaching:flush --model=App\Model
should be
php artisan modelCache:flush --model=App\Model
And I noticed that you HAVE to specify a model.. it would be very preferable to being able to flush all of the modelCache.. without having to flush the entire redis cache
could this be added please?
Code is already in place, all that is needed is the unit test to back it up.
I just updated to the latest version and now i have strange errors - maybe something todo with invalidation. (or not invalidating)
Example:
In my SalesController i prepare to add another product to the basket.
$saleItem = SaleItem::where('id','=',$request->get('id'))->first(); $product = Product::where('id',$request->get('product_id'))->first(); $saleItem->product_id = $product->id;
Now sometimes - mostly when more than one product is in the basket i get this error:
Property [id] does not exist on this collection instance.
(Regarding the line $product->id)
If i disable the cache everything is ok. Before i updated to the current version everything was fine, too.
What could be the problem over here. I have the same error on different Controllers - not only regarding products.. I disabled the whole cache now - because i'm getting many errors like these...
PHP 7.1
Laravel 5.5
latest package version
The cache key should consider dates and times passed within a query. For instance I am running a query like so that gets data between certain days and between certain hours of those days. Where $this represents a user model. I noticed that the cache comes back the same number of results for that user no matter the change in the query dates. Is this normal behavior or have I done something wrong on my end?
I am going to look into the laravel-model-caching package now.
Laravel Version: 5.6.3
Laravel Model Caching Package Version: ^0.2.22
PHP Version: 7.1.12
Homestead Version: N/A
Operating System & Version: Mac OS X High Sierra 10.13.3
$this->commissioned()
->whereDate( 'created_at', '>=', $start_date )
->whereDate( 'created_at', '<=', $end_date )
->whereTime( 'created_at', '>=', $start_time )
->whereTime( 'created_at', '<=', $end_time )
->paid()
->outbound()
->get();
When calling disableCache() on a query that uses a custom scope (I think this is what's causing it) it only works sometimes.
Laravel Version: 5.6.3
Laravel Model Caching Package Version: 0.2.33
PHP Version: 7.2.2
Homestead Version: N/A
Operating System & Version: macOS High Sierra 10.13.3
As you can see the following query works on and off. After it fails it will work and vice-versa.
The scope pendingGroupInvites is defined by:
public function scopePendingGroupInvites($query, $groupID)
{
return $query->where([['type', GroupInvite::class], ['data->group->id', $groupID]])->whereNull('data->action');
}
The following query always works:
Group::find(1)->users()->disableCache()->get();
In this case users is a many-to-many relationship.
As a final note, I'm using Redis.
Dude! This is so great!
I have created something similar myself in two different projects but this solves it in a much cleaner way. Glad to see your solutions! ๐
I wonder though, why do you force php 7.1? Why not go for the broader audience and allow also php 7.0?
Thanks again for sharing your stuff!
Example: $model->find(1);
appears it might not be cached, or might not respect disabling of the cache.
I have a model, Userwhich extends CachedModel:
class User extends CachedModel
{
}
Same model use Traits like Notifiable, Sluggable and CanFollow from package laravel-follow
class User extends CachedModel
{
use Notifiable, Sluggable, CanFollow, CanBeFollowed, CanLike, CanFavorite, CanSubscribe, EntrustUserTrait;
/**
The problem is that when User odel extends CachedModel, User model cant access the traits. I just realized that when i re-seeded an ongoing proyect.
>php artisan db:seed --class=LikesFollowersSeeder
In Builder.php line 2459:
Call to undefined method Illuminate\Database\Query\Builder::subscribe()
Laravel Version: 5.5.25
Laravel Model Caching Package Version: 0.2.12
PHP Version: 7.2.0
Homestead Version: N/A
Operating System & Version: Windows 10 64bits same on Ubuntu 16.04
Code is already in place, all you need to do is add the test. :)
This could be my setup/env but just wanted to check
Upgraded from 0.2.28 -> 0.2.42
Getting incorrect argument 1 (array expected, string given)
Laravel Version: 5.5.36
Laravel Model Caching Package Version: 0.2.42
PHP Version: 7.1.10
Homestead Version: N/A
Operating System & Version: Centos 7
Type error: Argument 1 passed to GeneaLabs\LaravelModelCaching\CachedBuilder::makeCacheKey() must be of the type array, string given, called in /Users/mattbridges/Code/test.com/vendor/genealabs/laravel-model-caching/src/CachedBuilder.php on line 30 (View: /Users/mattbridges/Code/test.com/resources/views/components/like-and-bookmarks.blade.php) (View: /Users/mattbridges/Code/test.com/resources/views/components/like-and-bookmarks.blade.php) (View: /Users/mattbridges/Code/test.com/resources/views/components/like-and-bookmarks.blade.php)
I am running a test using eloquent model and during test, I am getting this error:
Error : Call to undefined function GeneaLabs\LaravelModelCaching\Traits\emptyArray()
Laravel Version: v5.5.34
Laravel Model Caching Package Version: 0.2.26
PHP Version: PHP 7.1.11 (cli) (built: Oct 25 2017 21:07:06) ( ZTS MSVC14 (Visual C++ 2015) x86 )
Homestead Version: N/A I am using XAMPP
Operating System & Version: Windows 10 x64
Testing started at 23:37 ...
C:\xampp\php\php.exe C:/xampp/htdocs/myApp/vendor/phpunit/phpunit/phpunit --no-configuration Tests\Feature\Api\V1\OrganisationApiTest C:\xampp\htdocs\myApp\tests\Feature\Api\V1\OrganisationApiTest.php --teamcity
PHPUnit 6.5.6 by Sebastian Bergmann and contributors.
Error : Call to undefined function GeneaLabs\LaravelModelCaching\Traits\emptyArray()
C:\xampp\htdocs\myApp\vendor\genealabs\laravel-model-caching\src\Traits\Cachable.php:44
C:\xampp\htdocs\myApp\vendor\genealabs\laravel-model-caching\src\Traits\Cachable.php:75
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php:350
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php:200
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php:173
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasEvents.php:148
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php:598
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php:569
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:172
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Support\Collection.php:339
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:173
C:\xampp\htdocs\myApp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:153
C:\xampp\htdocs\myApp\tests\TestCase.php:28
C:\xampp\htdocs\myApp\tests\TestCase.php:18
C:\xampp\htdocs\myApp\tests\Feature\Api\V1\BaseApiTestCase.php:21
C:\xampp\htdocs\myApp\tests\Feature\Api\V1\OrganisationApiTest.php:11
Time: 1.54 seconds, Memory: 14.00MB
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Process finished with exit code 2
P.S. This works fine on version 0.2.25
This is important for migrations and seeders, but probably also useful in other situations.
Is there a possibility to delete only the model cache or even more specific to delete only one specific model cache? Would love to have a separate artisan command.
The reason is, that I don't like to clear all caches although I have just made on entry in one model out of 30.
Would that reduce the amount of select queries to the db?
Example issue just because of translations:
Shouldn't that be part of Laravel standard?
How can I integrate these in Vendor Models e.g. barryvdh/laravel-translation-manager#227 ?
How can I delete the cache e.g. when a change was made direct on the database?
Laravel Version: 5.5
PHP Version: 7
Thank you and a happy new year.
It has come to light that some tests are squeaking by and passing because of existing cache entries. We have fixed this where found, but will address this as a whole, so that we can check with confidence that this doesn't occur anywhere else.
I am using jenssegers/laravel-mongodb and using hybrid relations between mysql models and mongodb models
the mongodb models however rather than extend laravel's default model, extend a special wrapper model of sorts
a lot of model-related packages on github do work out of the box with mongodb models but I'm not sure how to use this one since it depends on extending a different model
any chance you could have a quick look at jenssegers/laravel-mongodb and see if there's a quick and easy solution to using it with your package?
thanks much!
Currently cache keys can be extraordinarily long, which might cause an issue if max key length is reached.
To prevent this, I had the idea of generating cache keys the same way they are now, but then using their hash as the key.
This will reduce key size, as well as obfuscate its content. (That would only be important for encrypted data, which it currently is not, but could also be a future consideration.)
I could see this being a quick little project for you. Please let me know your thoughts on the concept (pros/cons), and if you would be interested in it.
I was just wondering if you could clarify how the invalidation works exactly
from the docs you said that if you don't use a cache driver that supports tags, then anytime a new model is added the entire cache will be flushed
is it then the case that if you do use a driver that supports tags.. that anytime any user adds a new model (a comment for example) then this will trigger what exactly? all cache related to comments for all users will be flushed ?
it seems it would be useful to have a way to customize our own invalidation logic.. through the configuration file
perhaps this could serve as inspiration, another excellent caching package that I use
https://github.com/spatie/laravel-responsecache/blob/master/config/responsecache.php
another question please.. you say it's a bad idea to cache users.. I agree inherently but then if the invalidation works perfectly then why not exactly?
but in any case, let's say you don't cache the user model.. what about all the relations between the user and other models? if those models extend your CacheModel then the relations will be cached but not the user ?
Change badge to reflect master branch build status, not latest build status.
I have a model BannedIp - it extends CachedModel
When I delete a record using
BannedIp::where('id', 1)->delete();
The cache is not updated
Using a redis for my cache
namespace App;
use GeneaLabs\LaravelModelCaching\CachedModel;
class BannedIp extends CachedModel
{
}
It appears as if
static::deleted(function () use ($instance) {
$instance->flushCache();
});
in CachedModel.php is never hit
I'm trying a fresh install of laravel with a single model now to see if it's something specific to my laravel env
Laravel Version: 5.5.5
Laravel Model Caching Package Version: 0.2.10
PHP Version: 7.1.10
Homestead Version: N/A
Operating System & Version: OSX High Sierra 10.13.1
Code is already in place, all you need to do is add the test. :)
Laravel Version: 5.6.3
Laravel Model Caching Package Version: 0.2.33
PHP Version: 7.2.0
Homestead Version: -
Operating System & Version: macOs High Sierra 10.13.3
When using the paginate query there is a count query that not get cached
$articles = Article::paginate(30);
In the debug bar you see this query:
select count(*) as aggregate from articles
Add more detailed information for
Example:
$modelA->relationship()->get();
When using insert method for multiple records the cache doesn't invalidate.
The records successfully created, but not the cache.
I'm curious is there a way to clean up the cache from the controller side, not from the command line?
since the cache doesn't invalidate well..
Thanks
Laravel Version: 5.6.5
Laravel Model Caching Package Version: 0.2.35
PHP Version: 7.2.0-1
Homestead Version: x.y
Operating System & Version: Ubuntu16.04.1
$input = [
[
"product_id" => 2,
"user_id" => 51,
"quantity" => 1,
"information" => [
"color" => [
"id" => 1,
"name" => "White",
],
"size" => [
"id" => 1,
"name" => "S (Small)"
],
],
"branch" => "jakarta"
],
[
"product_id" => 4,
"user_id" => 51,
"quantity" => 1,
"information" => [
"color" => [
"id" => 2,
"name" => "Black",
],
"size" => [
"id" => 1,
"name" => "S (Small)",
]
],
"branch" => "jakarta"
]
];
return $this->cart->insert($input);
Switched from standard model to the CachedModel interface and immediately ran into a problem where I could not access the id of an entry if I had done some manual caching previously.
Laravel Version: 5.5.34
Laravel Model Caching Package Version: 0.2.21
PHP Version: 7.2
Homestead Version: N/A
Operating System & Version: Elementary OS Loki
No stack trace available
I have a complex query:
select * from `profiles` where (profiles.user_id not in(?) and profiles.active = 1)
and (profiles.user_id in(select user_id from user_interests where interest_id in(?))
or profiles.user_id in(select user_id from user_locations where region_id in(?))
or profiles.user_id in(select user_id from profiles where country_id = ?))
which I call like this:
$data['suggestedConnections'] = Profile::whereRaw('(profiles.user_id not in(?) and profiles.active = 1)
and (profiles.user_id in(select user_id from user_interests where interest_id in(?))
or profiles.user_id in(select user_id from user_locations where region_id in(?))
or profiles.user_id in(select user_id from profiles where country_id = ?))',
array($excludedIds, $includedInterests, $includedRegions, $location))
->limit(10)
->inRandomOrder()
->get();
$excludedIds, $includedInterests, $IncludedRegions are all arrays of ids
and $location is an integer.
I really don't want this query to be cached (or maybe a better way to put it is that I want this query to be excluded from the query cache, but I want the rest of the queries on the model to be cached).
I'm wondering if anything using a raw method https://laravel.com/docs/5.5/queries#raw-expressions should bypass the cache?
Alternatively is there a way I can clear that cache or skip caching or a given query?
Laravel Version: 5.5
Laravel Model Caching Package Version: 0.2.11
PHP Version: 7.1.10
Homestead Version: N/A
Operating System & Version: OSX High Sierra
For several of my custom local scoped queries across a number of different models I am getting Undefined index: operator
error. When I add disableCache()
to the queries the page works again. However, these queries could really be doing with the use of cache.
The query being run at the time of error in the below stack trace is this -
public function scopeBrandLinksForRange($query, int $brandId, string $range): int
{
$fromDate = Carbon::parse(explode(',', $range)[0]);
$tillDate = Carbon::parse(explode(',', $range)[1]);
return $query->whereBetween('created_at', [$fromDate, $tillDate])
->where('brand_id', $brandId)
->count();
}
Laravel Version: 5.5.34
Laravel Model Caching Package Version: 0.2.22
PHP Version: 7.1.11-1+ubuntu16.04.1+deb.sury.org+1
Homestead Version: N/A (Docker Development)
Operating System & Version: Ubuntu 16:04
{
"message": "Undefined index: operator",
"exception": "ErrorException",
"file": "/app/vendor/genealabs/laravel-model-caching/src/CacheKey.php",
"line": 95,
"trace": [
{
"file": "/app/vendor/genealabs/laravel-model-caching/src/CacheKey.php",
"line": 95,
"function": "handleError",
"class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
"type": "->"
},
{
"file": "/app/vendor/genealabs/laravel-model-caching/src/CacheKey.php",
"line": 154,
"function": "getTypeClause",
"class": "GeneaLabs\\LaravelModelCaching\\CacheKey",
"type": "->"
},
{
"file": "/app/vendor/genealabs/laravel-model-caching/src/CacheKey.php",
"line": 114,
"function": "getOtherClauses",
"class": "GeneaLabs\\LaravelModelCaching\\CacheKey",
"type": "->"
},
{
"function": "GeneaLabs\\LaravelModelCaching\\{closure}",
"class": "GeneaLabs\\LaravelModelCaching\\CacheKey",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Support/Collection.php",
"line": 1228,
"function": "array_reduce"
},
{
"file": "/app/vendor/genealabs/laravel-model-caching/src/CacheKey.php",
"line": 117,
"function": "reduce",
"class": "Illuminate\\Support\\Collection",
"type": "->"
},
{
"file": "/app/vendor/genealabs/laravel-model-caching/src/CacheKey.php",
"line": 28,
"function": "getWhereClauses",
"class": "GeneaLabs\\LaravelModelCaching\\CacheKey",
"type": "->"
},
{
"file": "/app/vendor/genealabs/laravel-model-caching/src/Traits/Cachable.php",
"line": 55,
"function": "make",
"class": "GeneaLabs\\LaravelModelCaching\\CacheKey",
"type": "->"
},
{
"file": "/app/vendor/genealabs/laravel-model-caching/src/CachedBuilder.php",
"line": 36,
"function": "makeCacheKey",
"class": "GeneaLabs\\LaravelModelCaching\\CachedBuilder",
"type": "->"
},
{
"file": "/app/app/Links/Models/Link.php",
"line": 236,
"function": "count",
"class": "GeneaLabs\\LaravelModelCaching\\CachedBuilder",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php",
"line": 953,
"function": "scopeBrandLinksForRange",
"class": "AdNews\\Links\\Models\\Link",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php",
"line": 1277,
"function": "callScope",
"class": "Illuminate\\Database\\Eloquent\\Builder",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php",
"line": 1470,
"function": "__call",
"class": "Illuminate\\Database\\Eloquent\\Builder",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php",
"line": 1482,
"function": "__call",
"class": "Illuminate\\Database\\Eloquent\\Model",
"type": "->"
},
{
"file": "/app/app/Http/Controllers/Api/Analytics/LinksController.php",
"line": 30,
"function": "__callStatic",
"class": "Illuminate\\Database\\Eloquent\\Model",
"type": "::"
},
{
"function": "getTotalBrandLinks",
"class": "AdNews\\Http\\Controllers\\Api\\Analytics\\LinksController",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
"line": 54,
"function": "call_user_func_array"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
"line": 45,
"function": "callAction",
"class": "Illuminate\\Routing\\Controller",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line": 212,
"function": "dispatch",
"class": "Illuminate\\Routing\\ControllerDispatcher",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line": 169,
"function": "runController",
"class": "Illuminate\\Routing\\Route",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 658,
"function": "run",
"class": "Illuminate\\Routing\\Route",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 30,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
"line": 41,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 149,
"function": "handle",
"class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php",
"line": 43,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 149,
"function": "handle",
"class": "Illuminate\\Auth\\Middleware\\Authenticate",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
"line": 57,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 149,
"function": "handle",
"class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 102,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 660,
"function": "then",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 635,
"function": "runRouteWithinStack",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 601,
"function": "runRoute",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 590,
"function": "dispatchToRoute",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 176,
"function": "dispatch",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 30,
"function": "Illuminate\\Foundation\\Http\\{closure}",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
"line": 46,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 149,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkMiddleware.php",
"line": 28,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 149,
"function": "handle",
"class": "Clockwork\\Support\\Laravel\\ClockworkMiddleware",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 102,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 151,
"function": "then",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 116,
"function": "sendRequestThroughRouter",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
},
{
"file": "/app/public/index.php",
"line": 55,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
}
]
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.