Closed
Description
Describe the bug
As the Model Article content field is stored the rich text with base64 encoded string, and an observer was created for encoding & decoding while saving and reading. It works fine until the trait mode Cachable involved in the Article model. And when it removed from the model, everything returned ok.
Eloquent Query
Please provide the complete eloquent query that caused the bug, for example:
Observer
/app/Observers/ArticleObserver.php
<?php
namespace App\Observers;
use App\Article;
class ArticleObserver
{
public function saving(Article $article)
{
$article->content = bin2hex($article->content);
}
public function retrieved(Article $article)
{
// if(strlen($article->content)%2==1 || preg_replace('/[a-zA-Z0-9]+/','',$article->content)!='')
// return;
try{
$article->content = hex2bin(trim($article->content));
}
catch (\Exception $e) {
return;
}
}
}
/app/Providers/ArticleModelServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ArticleModelServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
\App\Article::observe(\App\Observers\ArticleObserver::class);
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
Stack Trace
The full stack trace from your log file.
Environment
- PHP: [e.g. 7.1.0]
- OS: [e.g. Ubuntu 18.04]
- Laravel: [e.g. 5.6.15]
- Model Caching: [e.g. 0.2.61]
Additional context
Add any other context about the problem here.