【发布时间】:2021-03-16 03:52:15
【问题描述】:
这是我的代码,我想将图像 url 保存在数据库中我正在使用 laravel 我的问题是我如何将图像 url 保存在数据库中
公共函数保存(请求$req) { if(request()->hasFile('photo')){
$path = base_path() . '/public/user-uploads/employee-docs/';
$repath = '/public/user-uploads/employee-docs/'.request('project');
if (!file_exists($path))
{
mkdir($path);
}
$path = $path.'/'.request('project');
if (!file_exists($path))
{
mkdir($path);
}
$name = Carbon::now()->format('Y-m-d-H-i-s_u');
$file1 = request()->file('photo');
if($file1->isValid()) {
$file1->move($path, $name.'.'.$file1->getClientOriginalExtension());
$file1_url = $repath.'/'.$name.'.'.$file1->getClientOriginalExtension();
$photo = new attendance;
$photo ->user_id=$req->user_id;
$photo ->image_url=$req->image_url;
return ['status'=>1, 'data'=>$file1_url];
} else{
return ['status'=>0, 'data'=>'Invalid image'];
}
} else{
return ['status'=>0, 'data'=>'There is no image'];
}
}
【问题讨论】:
-
您没有保存对象并为图像 url 使用了错误的值。您是否收到任何特定错误??
-
“消息”:“发生未知错误”,
标签: laravel