I would like to save an image into a varbinary(max) field in MSSQL.
The store method in my controller looks like this:
public function store(Request $request)
{
$vorname = $request->input('vorname');
$nachname = $request->input('nachname');
$file = $request->file('avatar');
$extension = $file->clientExtension();
$fullname = $nachname . "_" . $vorname . "." . $extension;
$file->storeAs('avatars' , $fullname);
$path = storage_path() . "\app\avatars\\". $fullname;
$imageData = unpack("H*", file_get_contents($path));
Mitarbeiter::create([
'PersonalNr' => request('personalnr'),
'Mitarbeiterschluessel' => request('mitarbeiterkey'),
'Vorname' => $vorname,
'Familienname' => $nachname,
'Bild' => $imageData[1]
]);
return view('welcome');
}
I'm getting an error:
SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Die implizite Konvertierung vom nvarchar(max)-Datentyp in varbinary(max) ist nicht zulässig.
translated:
Implicit conversion from the nvarchar (max) data type to varbinary (max) is not allowed.
