TasksController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. class TasksController extends BaseController
  3. {
  4. public function home()
  5. {
  6. $tasks = Task::all();
  7. return View::make('home', compact('tasks'));
  8. }
  9. public function create()
  10. {
  11. return View::make('create');
  12. }
  13. public function edit(Task $task)
  14. {
  15. return View::make('edit', compact('task'));
  16. }
  17. public function delete(Task $task)
  18. {
  19. return View::make('delete', compact('task'));
  20. }
  21. public function saveCreate()
  22. {
  23. $input = Input::all();
  24. $rules = array(
  25. 'yourname'=> 'required',
  26. 'youremail'=> 'required',
  27. 'title'=> 'required',
  28. 'description'=> 'required'
  29. );
  30. $validator = Validator::make($input, $rules);
  31. if($validator->passes()) {
  32. $task = new Task;
  33. $task->yourname = Input::get('yourname');
  34. $task->youremail = Input::get('youremail');
  35. $task->title = Input::get('title');
  36. $task->description = Input::get('description');
  37. $task->case = Input::get('case');
  38. $task->save();
  39. return Redirect::action('TasksController@home')->withErrors($validator);
  40. }
  41. return Redirect::action('TasksController@create');
  42. }
  43. public function doEdit()
  44. {
  45. $task = Task::findOrFail(Input::get('id'));
  46. $task = new Task;
  47. $task->yourname = Input::get('yourname');
  48. $task->youremail = Input::get('youremail');
  49. $task->title = Input::get('title');
  50. $task->description = Input::get('description');
  51. $task->case = Input::get('case');
  52. $task->done = Input::get('done');
  53. $task->save();
  54. return Redirect::action('TasksController@home');
  55. }
  56. public function doDelete()
  57. {
  58. $task = Task::findOrFail(Input::get('id'));
  59. $task->delete();
  60. return Redirect::action('TasksController@home');
  61. }
  62. public function show($id)
  63. {
  64. $task = Task::find($id);
  65. return View::make('task', compact('task'));
  66. }
  67. }