app/Http/Controllers/Admin/MainCategoriesController.php
// DELETE A MAIN CATEGORY FROM DATABASE
DELETE A MAIN CATEGORY FROM DATABASE
DELETE A MAIN CATEGORY FROM DATABASE
public function destroy($mainCateID)
    {
        try {
            $mainCate = MainCate::find($mainCateID);
            if (!$mainCate) {
                return redirect()->route('admin.main.cates')->with([
                    'error' => 'No such main category'
                ]);
            }
            $vends = $mainCate->vendors();
            if (isset($vends) && $vends->count() > 0) {
                return redirect()->route('admin.main.cates')->with([
                    'error' => 'It\'s not allowed to delete this main category'
                ]);
            }
            DB::beginTransaction();
            deleteFile($mainCate->photo);
            $mainCate->delete();
            DB::commit();
            return redirect()->route('admin.main.cates')->with([
                'success' => 'Deleted Successfully'
            ]);
        } catch (\Throwable $th) {
            DB::rollback();
            return redirect()->route('admin.main.cates')->with([
                'error' => 'Something went terribly wrong'
            ]);
        }
    }
public function destroy ( $ mainCateID ) { try { $ mainCate = MainCate :: find ( $ mainCateID ) ; if ( ! $ mainCate ) { return redirect ( ) -> route ( 'admin.main.cates' ) -> with ( [ 'error' => 'No such main category' ] ) ; } $ vends = $ mainCate -> vendors ( ) ; if ( isset ( $ vends ) && $ vends -> count ( ) > 0 ) { return redirect ( ) -> route ( 'admin.main.cates' ) -> with ( [ 'error' => 'It\'s not allowed to delete this main category' ] ) ; } DB :: beginTransaction ( ) ; deleteFile ( $ mainCate -> photo ) ; $ mainCate -> delete ( ) ; DB :: commit ( ) ; return redirect ( ) -> route ( 'admin.main.cates' ) -> with ( [ 'success' => 'Deleted Successfully' ] ) ; } catch ( \ Throwable $ th ) { DB :: rollback ( ) ; return redirect ( ) -> route ( 'admin.main.cates' ) -> with ( [ 'error' => 'Something went terribly wrong' ] ) ; } }
DELETE A MAIN CATEGORY FROM DATABASE
DELETE A MAIN CATEGORY FROM DATABASE
// DATABASE MAIN CATEGORY ROW // DATABASE MAIN CATEGORY NOT EXIST CHECK // REDIRECT TO MAIN CATEGORIES TABLE WITH ERROR MESSAGE // MAIN CATEGORY'S VENDORS // MAIN CATEGORY HAS VENDORS CHECK // REDIRECT TO MAIN CATEGORIES TABLE WITH ERROR MESSAGE // START DATABASE TRANSACTIONS // DELETE MAIN CATEGORY IMAGE FROM SERVER // DATABASE MAIN CATEGORY DELETE STATEMENT // DATABASE COMMIT TRANSACTIONS // REDIRECT TO MAIN CATEGORIES TABLE WITH SUCCESS MESSAGE // DATABASE ROLL-BACK // REDIRECT TO MAIN CATEGORIES TABLE WITH ERROR MESSAGE