base64 (encode / decode) wont give errors like this, json_encode / decode however will.
It's probable that you are decoding the assumed base64 string, and if it wasnt encoded yet, it will still decode, resulting in a non UTF8 string.
After that, you are doing some json (_decode probably) which will fail because it is not a valid UTF8 string you are passing.
You might want to try this (not 100% though as it's pretty hard to check if a string is actually base64 encoded)
function base64_decode_if_needed($str)
{
$decoded = base64_decode($str, true);
if($str === base64_encode($decoded)) {
return $decoded;
}
return $str;
}
// use:
$message = Message::find(1);
dd( $message->message, base64_decode_if_needed($message->message) );
Also, you could put it in the Message model and use mutator methods (getter + setter) to do the conversion from within the model itself)
If you need more help, please post some code of where you are using it.