private function exportUsers() { $users = User::where('roles_id', '>=', '4')->select('id', 'roles_id', 'card as Tarjeta', 'identification_card as Cedula', 'name as Nombre1', 'second_name as Nombre2', 'last_name as Apellido1', 'second_last_name as Apellido2', 'email as Email', 'mobile_phone as Celular', 'location as Ciudad', 'created_at as Fecha de creación')->orderBy('roles_id', 'DESC')->get(); foreach ($users as $key => $user) { $credit = CreditRequest::where('user_id', $user->id)->first(); $users[$key]['Referencia1'] = $credit ? $credit->name_reference : null; $users[$key]['Tel_Referencia1'] = $credit ? $credit->phone_reference : null; $users[$key]['Referencia2'] = $credit ? $credit->name_reference2 : null; $users[$key]['Tel_Referencia2'] = $credit ? $credit->phone_reference2 : null; $users[$key]['Ciudad'] = $user->Ciudad ? Location::find($user->Ciudad)->name : 'Sin región'; $users[$key]['Tienda'] = $credit ? Point::find($credit->point)['name'] : 'Sin punto'; $users[$key]['Cupo_Credito'] = $credit ? $credit->value : null; $users[$key]['Emprend'] = $user->roles_id == 5 ? 'Si' : 'No'; $users[$key]['¿Empr. credito?'] = $credit && $user->roles_id == 5 ? 'Si' : $user->roles_id == 5 ? 'No' : 'N/A'; $users[$key]['Nombre referido'] = $user->roles_id == 5 ? $user['referred_name'] : 'N/A'; $users[$key]['Cedula referido'] = $user->roles_id == 5 ? $user['referred_document'] : 'N/A'; } return $users; }
public function deleteLocation($id) { $user = User::where('location', $id)->first(); $credit = CreditRequest::where('location', $id)->first(); if ($user or $credit) { return Redirect::route('location')->with(array('messages' => "No se pudo eliminar la region por que esta siendo usada")); } $location = Location::find($id); $location->delete(); new LogRepo(['responsible' => Auth::user()->user_name, 'action' => 'ha eliminado una region ', 'affected_entity' => 'Regiones', 'method' => 'deleteLocation']); return Redirect::route('location')->with(array('message' => "La region ha sido eliminada")); }