Last active
August 29, 2015 14:14
-
-
Save ratul0/2696a6891028cdd35fe9 to your computer and use it in GitHub Desktop.
laravel controller template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class BatchesController extends \BaseController { | |
| /** | |
| * Display a listing of batches | |
| * | |
| * @return Response | |
| */ | |
| public function index() | |
| { | |
| $batches = Batch::all(); | |
| return View::make('batches.index', compact('batches')); | |
| } | |
| /** | |
| * Show the form for creating a new batch | |
| * | |
| * @return Response | |
| */ | |
| public function create() | |
| { | |
| return View::make('batches.create'); | |
| } | |
| /** | |
| * Store a newly created batch in storage. | |
| * | |
| * @return Response | |
| */ | |
| public function store() | |
| { | |
| $validator = Validator::make($data = Input::all(), Batch::rules(),Batch::$messages); | |
| if ($validator->fails()) | |
| { | |
| return Redirect::back()->withErrors($validator)->withInput(); | |
| } | |
| $batch = new Batch; | |
| $batch->name = $data['name']; | |
| $batch->description = $data['description']; | |
| if($batch->save()){ | |
| return Redirect::route('batches.index'); | |
| }else{ | |
| return Redirect::back()->withErrors($validator)->withInput(); | |
| } | |
| } | |
| /** | |
| * Display the specified batch. | |
| * | |
| * @param int $id | |
| * @return Response | |
| */ | |
| public function show($id) | |
| { | |
| try{ | |
| $batch = Batch::findOrFail($id); | |
| return View::make('batches.show', compact('batch')); | |
| }catch (Exception $e){ | |
| return Redirect::route('batches.index')->with('error','Requested Page not exists.'); | |
| } | |
| } | |
| /** | |
| * Show the form for editing the specified batch. | |
| * | |
| * @param int $id | |
| * @return Response | |
| */ | |
| public function edit($id) | |
| { | |
| try{ | |
| $batch = Batch::findOrFail($id); | |
| return View::make('batches.edit', compact('batch')); | |
| }catch (Exception $e){ | |
| return Redirect::route('batches.index')->with('error','Requested Page not exists.'); | |
| } | |
| } | |
| /** | |
| * Update the specified batch in storage. | |
| * | |
| * @param int $id | |
| * @return Response | |
| */ | |
| public function update($id) | |
| { | |
| try{ | |
| $batch = Batch::findOrFail($id); | |
| }catch (Exception $e){ | |
| return Redirect::route('batches.index')->with('error','Some error occurred.'); | |
| } | |
| $validator = Validator::make($data = Input::all(), Batch::rules($id), Batch::$messages); | |
| if ($validator->fails()) | |
| { | |
| return Redirect::back()->withErrors($validator)->withInput(); | |
| } | |
| if($batch->update($data)){ | |
| return Redirect::route('batches.index')->with('success','Batch Updated successfully.'); | |
| }else{ | |
| return Redirect::back()->withErrors($validator)->withInput(); | |
| } | |
| } | |
| /** | |
| * Remove the specified batch from storage. | |
| * | |
| * @param int $id | |
| * @return Response | |
| */ | |
| public function destroy($id) | |
| { | |
| Batch::destroy($id); | |
| return Redirect::route('batches.index')->with('success','Batch Deleted successfully.'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment