mardi 27 septembre 2016

laravel 5 $image->delete() causing my code to stop

I ran into the problem that when i try to delete a record from database using ->delete() my code stopped after successfully deleted the record.

This code doesn't execute the Storage::delete($image)

public function productImageDelete(Request $request){
    if($request->ajax()):
        $image_id = Input::get('image-id');
        $image = Input::get('image');
        try {
            $image = Image::findOrFail($image_id);
            $image->delete();
            Storage::delete($image); //This doesn't execute at all
            return "success";
        } catch ( \Illuminate\Database\QueryException $e) {
            return $e;
        }
    endif;
}

However when i switched Storage::delete($image) before $image->delete(); the code works.

public function productImageDelete(Request $request){
if($request->ajax()):
    $image_id = Input::get('image-id');
    $image = Input::get('image');
    try {
        Storage::delete($image); //This executes first
        $image = Image::findOrFail($image_id);
        $image->delete();
        return "success";
    } catch ( \Illuminate\Database\QueryException $e) {
        return $e;
    }
endif;

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire