Closed pokemonhan closed 3 years ago
@harrisdt15f
Not sure if this fixes it for you - but i managed to get it working by adding the Service provider class added by genealabs in my unit test getPackageProviders method. Error appeared due to a class_alias not getting loaded before unit test ran.
protected function getPackageProviders($app)
{
return [OtherServiceProvider::class, \GeneaLabs\LaravelModelCaching\Providers\Service::class];
}
@harrisdt15f Unfortunately I am unable to replicate this issue. If you could submit a failing unit test, that would help immensely! :)
@mikebronner Its a PHP Warning so its not breaking the code but its still an inconvenient message to get. I am only getting this when running unit tests in my Laravel 8 application. It is specifically complaining about type hinting the $query
argument as the LaravelModelCaching\EloquentBuilder
instead of the Eloquent\Builder
.
PHP Warning: Declaration of GeneaLabs\LaravelModelCaching\Traits\Cachable::newBelongsToMany(
GeneaLabs\LaravelModelCaching\EloquentBuilder $query,
Illuminate\Database\Eloquent\Model $parent,
$table,
$foreignPivotKey,
$relatedPivotKey,
$parentKey,
$relatedKey,
$relationName = NULL) should be compatible with Illuminate\Database\Eloquent\Model::newBelongsToMany(
Illuminate\Database\Eloquent\Builder $query,
Illuminate\Database\Eloquent\Model $parent,
$table,
$foreignPivotKey,
$relatedPivotKey,
$parentKey,
$relatedKey,
$relationName = NULL) in /Users/xxxx/PhpstormProjects/TMC-BACKEND/site/app/Models/CurrencyModelsBestTrackerSetting.php
on line 45
Locally I changed the $query
argument locally to match Model::newBelongsToMany
in ModelCaching::newBelongsToMany
and the message goes away.
@dmason30 Your warning looks different. I get the same error as @harrisdt15f and it stops my application from working. It currently prevents us from upgrading to Laravel 8.
@roelVerdonschot Ok so I was running on PHP 7.3 for the above issue. It appears that the message has changed between PHP 7.3 and 7.4.
I have setup an example repo (see link below) and if you click on the "Executing PHP Tests" section on both the PHP 7.3 and PHP 7.4 runs and you can see it outputs both variations of the message but on PHP 7.4 it is not stopping script execution. Could this be down to PHP configuration?
https://github.com/dmason30/model-caching-example/runs/1359149642?check_suite_focus=true
@mikebronner I hope this serves as proof that this issue exists and can be replicated. I will do a PR and run the fix in my example repo to show that these messages no longer occur.
I have created a PR here with before and after comparisons using the example repo mentioned above.
Describe the bug I got the below error when I installed on laravel 8.
Warning: Could not check compatibility between GeneaLabs\LaravelModelCaching\Traits\Cachable::newBelongsToMany(GeneaLabs\LaravelModelCaching\EloquentBuilder $query, Illuminate\Database\Eloquent\Model $parent, $table, $foreignPivotKey, $relatedPivotKey, $parentKey, $relatedKey, $relationName = NULL) and Illuminate\Database\Eloquent\Model::newBelongsToMany(Illuminate\Database\Eloquent\Builder $query, Illuminate\Database\Eloquent\Model $parent, $table, $foreignPivotKey, $relatedPivotKey, $parentKey, $relatedKey, $relationName = NULL), because class GeneaLabs\LaravelModelCaching\EloquentBuilder is not available in /var/www/jianghu_entertain/app/Models/BaseModel.php on line 110
Environment
Additional context
![image](https://user-images.githubusercontent.com/27404296/96617117-c852dc00-1335-11eb-8e47-a239d76d9a6e.png)