<?php

class $NAME$ extends \BaseController {

	/**
	 * Display a listing of $COLLECTION$
	 *
	 * @return Response
	 */
	public function getIndex()
	{
		$$COLLECTION$ = $MODEL$::all();

		return View::make('$COLLECTION$.index', compact('$COLLECTION$'));
	}

	/**
	 * Show the form for creating a new $RESOURCE$
	 *
	 * @return Response
	 */
	public function getCreate()
	{
		return View::make('$COLLECTION$.create');
	}

	/**
	 * Store a newly created $RESOURCE$ in storage.
	 *
	 * @return Response
	 */
	public function postStore()
	{
		$validator = Validator::make($data = Input::all(), $MODEL$::$rules);

		if ($validator->fails())
		{
			return Redirect::back()->withErrors($validator)->withInput();
		}

		$MODEL$::create($data);

		return Redirect::action('$NAME$@getIndex');
	}

	/**
	 * Display the specified $RESOURCE$.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function getShow($id)
	{
		$$RESOURCE$ = $MODEL$::findOrFail($id);

		return View::make('$COLLECTION$.show', compact('$RESOURCE$'));
	}

	/**
	 * Show the form for editing the specified $RESOURCE$.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function getEdit($id)
	{
		$$RESOURCE$ = $MODEL$::find($id);

		return View::make('$COLLECTION$.edit', compact('$RESOURCE$'));
	}

	/**
	 * Update the specified $RESOURCE$ in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function postUpdate($id)
	{
		$$RESOURCE$ = $MODEL$::findOrFail($id);

		$validator = Validator::make($data = Input::all(), $MODEL$::$rules);

		if ($validator->fails())
		{
			return Redirect::back()->withErrors($validator)->withInput();
		}

		$$RESOURCE$->update($data);

		return Redirect::action('$NAME$@getIndex');
	}

	/**
	 * Remove the specified $RESOURCE$ from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function getDestroy($id)
	{
		$MODEL$::destroy($id);

		return Redirect::action('$NAME$@getIndex');
	}

}
