mentors

mentors Git Source Tree


Root/app/controllers/MentorController.php

<?php


class MentorController extends \BaseController {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		$mentors = Mentor::all();

		return \View::make('mentors.index')->with('mentors', $mentors);
	}


	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		return \View::make('mentors.create');
	}


	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		$rules = array(
			'name'       => 'required',
			'email'      => 'required|email',
			'title' => 'required'
		);
		$validator = Validator::make(Input::all(), $rules);

		// process the login
		if ($validator->fails()) {
			return Redirect::to('mentors/create')
				->withErrors($validator)
				->withInput(Input::except('password'));
		} else {
			// store
			$nerd = new Mentor;
			$nerd->name       = Input::get('name');
			$nerd->email      = Input::get('email');
			$nerd->title = Input::get('title');
			$nerd->save();

			// redirect
			Session::flash('message', 'Successfully created nerd!');
			return Redirect::to('mentors');
		}
	}


	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		// get the nerd
		$mentor = Mentor::find($id);

		// show the view and pass the nerd to it
		return View::make('mentors.show')
			->with('mentor', $mentor);
	}


	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		// get the nerd
		$mentor = Mentor::find($id);

		// show the edit form and pass the nerd
		return View::make('mentors.edit')
			->with('mentor', $mentor);
	}


	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		// validate
		// read more on validation at http://laravel.com/docs/validation
		$rules = array(
			'name'       => 'required',
			'email'      => 'required|email',
			'title' => 'required'
		);
		$validator = Validator::make(Input::all(), $rules);

		// process the login
		if ($validator->fails()) {
			return Redirect::to('mentors/' . $id . '/edit')
				->withErrors($validator)
				->withInput(Input::except('password'));
		} else {
			// store
			$mentor = Mentor::find($id);
			$mentor->name       = Input::get('name');
			$mentor->email      = Input::get('email');
			$mentor->title = Input::get('title');
			$mentor->save();

			// redirect
			Session::flash('message', 'Successfully updated mentor!');
			return Redirect::to('mentors');
		}
	}


	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		// delete
		$mentor = Mentor::find($id);
		$mentor->delete();

		// redirect
		Session::flash('message', 'Successfully deleted the mentor!');
		return Redirect::to('mentors');
	}


}

Archive Download this file

Branches

Number of commits:
Page rendered in 0.14474s using 11 queries.