Skip to content

Commit

Permalink
V2
Browse files Browse the repository at this point in the history
  • Loading branch information
maged-web committed May 4, 2024
1 parent bc21437 commit eed68b8
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions app/Http/Controllers/HouseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,33 @@ public function store(Request $request)

public function update(Request $request, House $house)
{
$fileOld=$house->photo;
$filename = $request->file('photo')->store('houses');

// TASK: Delete the old file from the storage
if($house->photo)
{
Storage::delete($house->photo);
}

$house->update([
'name' => $request->name,
'photo' => $filename,
]);

if($fileOld && !$fileOld==$filename)
{
Storage::delete($fileOld);
}
return 'Success';
}

public function download(House $house)
{
// TASK: Return the $house->photo file from "storage/app/houses" folder
// for download in browser
$filePath=storage_path('app/houses' . $house->photo);
$filePath = storage_path("app/houses/{$house->photo}");
if(file_exists($filePath))
{
return response()->download($filePath);

}
else
abort(404, 'File not found');

else {
return response()->json(['error' => 'File not found'], 404);
}
}
}
}

0 comments on commit eed68b8

Please sign in to comment.