CRUD가 업로드 한 파일의 이름 대신 데이터베이스에 이미지 바이너리를 저장하려고하는 이유를 알 수 없습니다.Laravel Backpack 이미지 필드 오류 : 1406 데이터가 너무 길어서
모델
public function setImageAttribute($value)
{
$attribute_name = "image_wheel";
$disk = "wheel";
$destination_path = "wheel_png";
// if the image was erased
if ($value==null) {
// delete the image from disk
\Storage::disk($disk_wheel)->delete($this->{$image_wheel});
\Storage::disk($disk_vehicle)->delete($this->{$image_vehicle});
// set null in the database column
$this->attributes[$image_wheel] = null;
$this->attributes[$image_vehicle] = null;
}
// if a base64 was sent, store it in the db
if (starts_with($value, 'data:image'))
{
// 0. Make the image
$image = \Image::make($value);
// 1. Generate a filename.
$filename = md5($value.time()).'.jpg';
// 2. Store the image on disk.
\Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
// 3. Save the path to the database
$this->attributes[$attribute_name] = $destination_path.'/'.$filename;
}
}
오류 메시지
Next Illuminate\Database\QueryException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'image_wheel' at row 1 (SQL: insert into
wheels
(name
,part_no
,alias
,series_id
,sizes
,image_wheel
,image_vehicle
,description
,order
,status
,featured
,-wheel_image_id
,-wheel_tags
,updated_at
,created_at
) values (, , , , , data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/ ...........
열의 데이터 유형을 변경해야합니다. – Arafath
이'image_wheel' 필드의 정의는 무엇입니까 – lagbox
@Arafath \t 이미지의 바이너리 대신 md5 ($ value.time()) .jpg라는 이름을 저장하면 안됩니까? – cvassios