I have a an update function for my courses that looks like this [code below] .. It is supposed to check if an old picture exists and if it does, it overwrites it with a new one. the function works perfectly fine on localhost but on server, it just deletes the old picture and does not update.
//update course Image
public function updateCourseCard(Request $request,$id){
Validator::make($request->all(),['crs_img'=>"required|file|image|mimes:jpg,png,jpeg|max:5000"])->validate();
if($request->hasFile("crs_img")){
$course = Course::find($id);
$exists = Storage::disk('local')->exists("public/courses/".$course->crs_img);
//delete old image
if($exists){
Storage::disk("local")->delete('public/courses/'.$course->crs_img);
}
//upload new image
$ext = $request->file('crs_img')->getClientOriginalExtension(); //jpg
$request->crs_img->storeAs("courses/",$course->crs_img);
$arrayToUpdate = array('crs_img'=>$course->crs_img,
'updated_at' => \Carbon::now());
DB::table('courses')->where('id',$id)->update($arrayToUpdate);
return redirect()->route("adminAllCourses")->withSuccess('Course Image Updated!');
}else{
$error = "NO Image was Selected";
return $error;
}
}
I made sure that I ran php artisan storage link on my SSH server. I am using Digital ocean .. what is the issue here ? is it a permission issue or what ?
When I ran storage link again i got
The [/public/storage] link already exists.
The links have been created.