/** * Remove the specified resource from storage. * @param type int $id * @return type Response */ public function destroy($id, Organization $org) { try { // User_org /* select the field by id */ $orgs = $org->whereId($id)->first(); /* Delete the field selected from the table */ /* Check whether function success or not */ if ($orgs->delete() == true) { /* redirect to Index page with Success Message */ return redirect('organizations')->with('success', 'Organization Deleted Successfully'); } else { /* redirect to Index page with Fails Message */ return redirect('organizations')->with('fails', 'Organization can not Delete'); } } catch (Exception $e) { /* redirect to Index page with Fails Message */ return redirect('organizations')->with('fails', 'Organization can not Delete'); } }
/** * Delete a specified organization from storage. * @param type int $id * @return type Redirect */ public function destroy($id, Organization $org, User_org $user_org) { /* select the field by id */ $orgs = $org->whereId($id)->first(); $user_orgs = $user_org->where('org_id', '=', $id)->get(); foreach ($user_orgs as $user_org) { $user_org->delete(); } /* Delete the field selected from the table */ /* Check whether function success or not */ try { $orgs->delete(); /* redirect to Index page with Success Message */ return redirect('organizations')->with('success', 'Organization Deleted Successfully'); } catch (Exception $e) { /* redirect to Index page with Fails Message */ return redirect('organizations')->with('fails', $e->errorInfo[2]); } }