I'm working on a project and I want to use encrypt/decrypt for database values. I encrypted the 'email' field, and it works fine, but when I want to run this query I got an error.
The query: Users::where('email', '[email protected]')->get()
; -> in this query I want to get a row where the email is [email protected]
The error: The data types text and nvarchar are incompatible in the equal to operator. (SQL: select * from [users] where [email] = [email protected])"
I tried to CAST it or CONVERT it, but that doesn't work either. Can someone help me how to run this query?
Here is my model:
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class Users extends Model
{
use HasFactory, Notifiable;
protected $table = 'users';
public $timestamps = false;
protected $fillable = [
'username',
'pwd',
'email'
];
protected $casts = [
'email' => 'encrypted'
];
}
Thanks for your answers!