l5-repository
l5-repository copied to clipboard
"Serialization of 'Illuminate\Http\UploadedFile' is not allowed"
I Need help to solve this error
Exception Serialization of 'Illuminate\Http\UploadedFile' is not allowed
vendor\prettus\l5-repository\src\Prettus\Repository\Traits\CacheableRepository.php
- Serialize single criterion with customized serialization of Closures.
*
-
@param \Prettus\Repository\Contracts\CriteriaInterface $criterion
-
@return \Prettus\Repository\Contracts\CriteriaInterface|array
-
@throws \Exception */ protected function serializeCriterion($criterion) { try { serialize($criterion);
return $criterion;
} catch (Exception $e) { // We want to take care of the closure serialization errors, // other than that we will simply re-throw the exception. if ($e->getMessage() !== "Serialization of 'Closure' is not allowed") { throw $e; }
$r = new ReflectionObject($criterion); return [ 'hash' => md5((string) $r), 'properties' => $r->getProperties(),
-
I do get the same error. I had to disable caching for now. I hope I get around to take a closer look at it in the next few days and make a pull request if i find something.
I tried to verify why this was happening and could not identify anything.
I'm waiting for correction.
same issue
bump
Same issue. Someone found a solution?
@zepaduajr Can you paste your code, and explain where the error ocurred?
@eullercdr i've sent a request with uploaded file.
When i do any querys in repository (using CacheableRepository), i receive this error:
(1/1) Exception
Serialization of 'Illuminate\Http\UploadedFile' is not allowed
--
in CacheableRepository.php (line 161)
This error occurs when request is serialized: (inside CacheableRepository.php)
public function getCacheKey($method, $args = null)
{
$request = app('Illuminate\Http\Request');
---> $args = serialize($args); <---
$criteria = $this->serializeCriteria();
$key = sprintf('%s@%s-%s', get_called_class(), $method, md5($args . $criteria . $request->fullUrl()));
CacheKeys::putKey(get_called_class(), $key);
return $key;
}
In my request:
Request $request;
$request->files->parameters['blb_file'] (UploadedFile)
My solution was to create a "Disable Caching" middleware and apply it to my route.
config(['repository.cache.enabled' => false]);
i add "skipCache=true" in files upload routes
my solution is modify serializeCriteria method in CacheableRepository.php just use try cache to ignore the error
try {
return serialize($this->getCriteria());
} catch (Exception $e) {
return serialize($this->getCriteria()->map(function ($criterion) {
/** add here */
try {
return $this->serializeCriterion($criterion);
} catch (Exception $e) {
Log::warning($e->getMessage());
}
}));
}
The same issue, Plz fix it!