【发布时间】:2021-02-13 10:24:08
【问题描述】:
仅当用户更改任何内容时才更新数据,否则会返回没有更新的消息。单击编辑按钮后,如果用户点击更新按钮而没有更改任何内容,则返回没有更新的消息。 如果用户更改了编辑表单中的任何内容,那么它将被更新。
我试过了
( I have multiple fields. This is for demo)
if ($user->name == $request->name && $user->email == $request->email && $user->contact ==
$request>contact) {
return back()->with('info', 'You have not change anything. Nothing to update!');
} else {
$user->update([
'name' => $request->name,
'email' => $request->email,
'contact' => $request->contact,
'image' => $image,
]);
}
return redirect()->route('admin.home')->with('success', 'Profile has been updated');
除了图片之外,这个工作很好。
这是我的图片上传过程
if ($request->has('image')) {
Storage::delete('public/avatar/users/' . $user->image);
$image_name = hexdec(uniqid());
$ext = strtolower($request->image->getClientOriginalExtension());
$image_full_name = $image_name . '.' . $ext;
$request->image->storeAs('avatar/users/', $image_full_name, 'public');
$image = $image_full_name;
} else {
$image = $user->image;
}
如何使用图像执行此操作?最好的方法是什么?
【问题讨论】:
-
什么是
$image和$user->$image?一条路? -
$image =$request->image,
-
好的,那么
$request->image是什么?服务器上图片的路径? -
不,图片来自编辑表单
-
请发布处理图像上传过程的代码,因为我们无法确定您是使用 LOB 还是处理上传并将其移动到使用原始文件名等路径,@987654326 @ 或者如果它只是一个 URL 等。
标签: php mysql laravel eloquent