Demo entry 3321242

hph

   

Submitted by php on Dec 14, 2015 at 19:29
Language: PHP. Code size: 4.3 kB.

<?php

class UsersController extends \BaseController {

	/**
	 * Display a listing of the resource.
	 * GET /users
	 *
	 * @return Response
	 */
	public function index()
	{
		//
	}

	/**
	 * Show the form for creating a new resource.
	 * GET /users/create
	 *
	 * @return Response
	 */
	public function create()
	{
		//
		
	}

	/**
	 * Store a newly created resource in storage.
	 * POST /users
	 *
	 * @return Response
	 */
	public function store()
	{
		//
		$userdata = Input::all();
		$user = new User();
		if($user->isValid($userdata))
		{
			$user->fill($userdata);
			if($user->save())
			{
				return Redirect::back()->with('mensaje', 'El usuario ha sido registrado existosamente!');
			}
		}else{
			return Redirect::back()->withInput()->withErrors($user->errors);
		}
	}

	/**
	 * Display the specified resource.
	 * GET /users/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
		if(Auth::user()->rol_id == 1)
		{

			if($id == 'd')
			{
				$id = 2;
				$users = User::where('rol_id', $id)->get();

				User::where('rol_id', $id);
				

				return View::make('users.index')->with('users', $users);
			}
			elseif($id == 'e'){
				$id = 3;
				$users = User::where('rol_id', $id)->get();
				return View::make('users.index')->with('users', $users);
			}
			elseif($id == 'p'){
				$id = 4;
				$users = User::where('rol_id', $id)->get();
				return View::make('users.index')->with('users', $users);
			}
			else{
				$user = User::find($id);
				if(count($user)>0)
				{
					return View::make('users.show')->with('user', $user);
				}
				App::missing(function($exception)
				{
				    return Response::view('errors.missing', array(), 404);
				});
			}
		}elseif(Auth::user()->rol_id == 2){
			if($id == 'p'){
				$id = 4;
				$users = User::where('rol_id', $id)->get();
				return View::make('users.index')->with('users', $users);
			}else{
				$user = User::find($id);
				if(count($user)>0)
				{
					return View::make('users.show')->with('user', $user);
				}
				App::missing(function($exception)
				{
				    return Response::view('errors.missing', array(), 404);
				});
			}
		}elseif(Auth::user()->rol_id == 3){
			if($id == 'p'){
				$id = 4;
				$users = User::where('rol_id', $id)->get();
				return View::make('users.index')->with('users', $users);
			}else{
				$user = User::find($id);
				if(count($user)>0)
				{
					return View::make('users.show')->with('user', $user);
				}
				App::missing(function($exception)
				{
				    return Response::view('errors.missing', array(), 404);
				});
			}
		}
		else{
			return Redirect::to('/');
		}
	}

	/**
	 * Show the form for editing the specified resource.
	 * GET /users/{id}/edit
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
		$user = User::find($id);
		if(count($user)>0)
		{
			return View::make('users.edit')->with('user', $user); 
		}else{
			return Redirect::back()->with('error', 'Usuario no disponible');
		}
	}

	/**
	 * Update the specified resource in storage.
	 * PUT /users/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
		$user = User::findOrFail($id);
		$userdata = Input::all();
		if($user->isValidUpdate($userdata))
		{
			$user->fill($userdata);
			if($user->save())
			{
				return Redirect::to('/admin/user/'.$id )->with('mensaje', 'Usuario actualizado correctamente');
			}
		}else{
			return Redirect::back()->withInput()->withErrors($user->errors);
		}
		
	}

	/**
	 * Remove the specified resource from storage.
	 * DELETE /users/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}

	public function createPaciente()
	{
		return View::make('users.create')->with('tipo', 'paciente');
	}

	public function createDoctor()
	{
		return View::make('users.create')->with('tipo', 'doctor');
	}
	public function createEnfermera()
	{
		return View::make('users.create')->with('tipo', 'enfermera');
	}
	public function createRecepcionista()
	{
		return View::make('users.create')->with('tipo', 'recepcionista');
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).