/** * Display a listing of the resource. * * @return Response */ public function postServicios(Request $request) { // var_dump($request->input('key')); switch ($request->input('get')) { case 'findByKey': $input = e($request->input('key')); if (!empty($input)) { echo Servicio::where('name', 'like', '%' . $input . '%')->get()->toJson(); } break; case 'byUser': $user = $request->input('id'); echo UserMeta::where('id', '=', $user)->where('name', '=', 'servicios')->get()->toJson(); // print_r(UserMeta::all()); // echo UserMeta::where('id','=',$user)->where('name','=','servicios')->get()->toJson(); break; case 'saveChanges': $collection = json_encode($request->input('collection')); $id = $request->input('id'); $meta = UserMeta::where('id', '=', $id)->where('name', '=', 'servicios')->get(); $array = $meta->toArray(); if (empty($array)) { $newMeta = new UserMeta(); $newMeta->id = $id; $newMeta->data = $collection; $newMeta->name = 'servicios'; echo $newMeta->save(); } else { $result = DB::table('user_metas')->where('id', $id)->where('name', 'servicios')->update(['data' => $collection]); echo $result; } break; case 'all': $services = Servicio::where('state', '=', 'active')->get()->toArray(); foreach ($services as $k => $v) { // $date = new DateTime($services[$k]['created_at']); $date = date_create($v['created_at']); $categorias = json_decode($v['categorias']); $services[$k]['categorias'] = array(); $services[$k]['usuario'] = User::find($v['user_id']); $services[$k]['created_at'] = date_format($date, 'd/m/Y'); foreach ($categorias as $kc => $vc) { if (!is_null($vc) && !empty($vc) && is_numeric($vc)) { $array = array(); $array['id'] = $vc; $array['name'] = Categoria::find($vc)->name; array_push($services[$k]['categorias'], $array); } } } echo json_encode(array_reverse($services)); break; default: # code... break; } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { //id del usuario logueado $id_logueado = Auth::user()->id; if (Auth::user()->nivel === 'cliente') { return redirect('inicioCliente'); } elseif (Auth::user()->nivel === 'tecnico') { $servicio = Servicio::where('tecnico_id', $id_logueado)->orderBy('id', 'DESC')->paginate(5); } else { $servicio = Servicio::orderBy('id', 'DESC')->paginate(5); } return view('servicios.index')->with('servicio', $servicio); }
public function inicio() { //id del usuario logueado $id_logueado = Auth::user()->id; if (Auth::user()->nivel === 'cliente') { $servicio = Servicio::where('cliente_id', $id_logueado)->orderBy('updated_at', 'DESC')->take(5)->get(); $cantidad = count($servicio); return view('inicioCliente')->with('servicio', $servicio)->with('cantidad', $cantidad); } else { if (Auth::user()->nivel === 'tecnico') { $servicio = Servicio::where('tecnico_id', $id_logueado)->get(); $cantidad = count($servicio); return view('inicioTecnico')->with('servicio', $servicio)->with('cantidad', $cantidad); } else { if (Auth::user()->nivel === 'administrador') { $tecnicos = User::where('nivel', 'tecnico')->count(); $clientes = User::where('nivel', 'cliente')->count(); $registrados = Servicio::count(); $concluidos = Servicio::where('status', 3)->count(); return view('inicioAdmin')->with('tecnicos', $tecnicos)->with('clientes', $clientes)->with('registrados', $registrados)->with('concluidos', $concluidos); } } } }
/** * Searches for an especific service name * @param Request $request * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed */ public function search(Request $request) { $servicios = Servicio::where("name", 'like', '%' . $request->input("search") . '%')->orWhere("id", $request->input("search"))->orderBy('created_at', 'desc')->paginate(10); return view("servicios.index", compact("servicios")); }