When I'am updating image/file database doesn't save path but only temporary path that looks like "C:\xampp\tmp\php4831.tmp"
. It's must be saved in database like"C:\xampp\htdocs\advertisment\public\public/ad_imag..."
I use PHP and Laravel 5.7.Here is part of code of my update method in controller.
$car = Car::find($id); // finding'id' of subject
$car->name = $request->name;
if($file = $request->hasFile('car_photo')) {
unlink($car->car_photo); //deletes previous file
}
//uploads new file
$request->file('car_photo')->move(public_path('public/ad_images'),
$request->file('car_photo')->getClientOriginalName());
try {
Car::find($id)->update($request->all());
dd($car);
return response()->json(
Json::construct
'Resource updated succesfully',
201,
['car' => $data]
),
201
);
......
...
The problem is record in database which is like: C:\xampp\tmp\php4831.tmp
,
but it needs to be like: C:\xampp\htdocs\advertisment\public\public/ad_images
.
Thanks in advance for help.