Created
May 23, 2017 07:22
-
-
Save cyberfly/75fd91fb8de6cee49eae77e149efdde9 to your computer and use it in GitHub Desktop.
Check if Object has relationship data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class UsersController extends Controller | |
| { | |
| public function deleteUser($id,Request $request) | |
| { | |
| try { | |
| $user = User::findOrFail($id); | |
| //only allowed delete user that have no evaluation | |
| if ($user->companies()->count()) { | |
| return response()->json(['result'=>'error', 'message'=>'not allowed to delete user with evaluation']); | |
| } | |
| else{ | |
| $user->delete(); | |
| return response()->json(['result'=>'success']); | |
| } | |
| } | |
| catch (QueryException $e) { | |
| return $this->response->errorBadRequest('Error while deleting.'); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment