猿问

从数据库删除或从服务器删除中只有一个功能在起作用

我正在尝试删除帖子的图像,但是我只执行一个动作。从数据库删除或从文件夹/服务器删除。


两种动作都工作正常,但我只把它放在第一位。


注意:我通过Blade / View的Ajax Get Request调用此Controller函数


public function deletePermanently(){

    $id = Input::get('id');

    Photo::where('post_id',$id)->delete();

    $obj = Post::with(['pictures'])->find($id);

    $filePath = public_path().'/upload/';

    if(count($obj->pictures) > 0){

        foreach($obj->pictures as $photo){

            if(file_exists($filePath.$photo->name)){                                       

                unlink($filePath.$photo->name);                    

            }


        }

    }

}

我希望一次从数据库和文件夹/服务器中删除


临摹微笑
浏览 107回答 3
3回答

桃花长相依

你可以这样尝试use Illuminate\Support\Facades\Storage; Storage::delete('file.jpg');
随时随地看视频慕课网APP
我要回答