Skip to content

Instantly share code, notes, and snippets.

@cyberfly
Created May 23, 2017 07:22
Show Gist options
  • Select an option

  • Save cyberfly/75fd91fb8de6cee49eae77e149efdde9 to your computer and use it in GitHub Desktop.

Select an option

Save cyberfly/75fd91fb8de6cee49eae77e149efdde9 to your computer and use it in GitHub Desktop.
Check if Object has relationship data
<?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