conditional logic

Posted 7 months ago by psychosocial227

This destroy method work perfectly well using laravel framework to delete a single file.

  • public function destroy(portfolio $portfolio) { if(Storage::disk('public')->exists('portfolio/'.$portfolio->cover) { Storage::disk('public')->delete('portfolio/'.$portfolio->cover); } $portfolio->delete(); Session::flash('status', 'Portfolio deleted succesfully'); return redirect()->back(); } }

But i have 4 file that i will like to delete how do one pass such logic and this what i have tried.

*public function destroy(portfolio $portfolio)
    {

        if(Storage::disk('public')->exists('portfolio/'.$portfolio->cover && Storage::disk('public')->exists('portfolio/'.$portfolio->detail_1) &&
        (Storage::disk('public')->exists('portfolio/'.$portfolio->detail_2 && Storage::disk('public')->exists('portfolio/'.$portfolio->detail_3) ) {
        
            Storage::disk('public')->delete('portfolio/'.$portfolio->cover);
            Storage::disk('public')->delete('portfolio/'.$portfolio->detail_1);
            Storage::disk('public')->delete('portfolio/'.$portfolio->detail_2);
            Storage::disk('public')->delete('portfolio/'.$portfolio->detail_3);
        }
        $portfolio->delete();
        Session::flash('status', 'Portfolio deleted succesfully');
        return redirect()->back();
    }
}*

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.