Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Http\Requests;
  7. use App\Http\Controllers\Controller;
  8. use App\Marker;
  9.  
  10. class MarkerController extends Controller
  11. {
  12. public function index()
  13. {
  14. $markers = Marker::all();
  15.  
  16. return view('markers.index', ['markers' => $markers]);
  17. }
  18.  
  19. public function create()
  20. {
  21. return view('markers.create');
  22. }
  23.  
  24. public function store(Request $request)
  25. {
  26. $rules = array(
  27. 'name' => 'required',
  28. 'x' => 'required|numeric',
  29. 'y' => 'required|numeric'
  30. );
  31. $validator = Validator::make(Input::all(), $rules);
  32.  
  33. if ($validator->fails()) {
  34. return Redirect::to('markers/create')
  35. ->withErrors($validator)
  36. ->withInput();
  37. } else {
  38. $marker = new Marker;
  39. $marker->name = Input::get('name');
  40. $marker->x = Input::get('x');
  41. $marker->y = Input::get('y');
  42. $marker->save();
  43.  
  44. Session::flash('message', 'Successfully created marker!');
  45. return Redirect::to('markers');
  46. }
  47. }
  48.  
  49. public function show($id)
  50. {
  51. $marker = Marker::find($id);
  52. return view('markers.show', compact('marker'));
  53. }
  54.  
  55. public function edit($id)
  56. {
  57. $marker = Marker::find($id);
  58. return view('markers.edit', compact('marker'));
  59. }
  60.  
  61. public function update(Request $request, $id)
  62. {
  63. $rules = array(
  64. 'name' => 'required',
  65. 'x' => 'required|numeric',
  66. 'y' => 'required|numeric'
  67. );
  68. $validator = Validator::make(Input::all(), $rules);
  69.  
  70. if ($validator->fails()) {
  71. return Redirect::to('markers/' . $id . '/edit')
  72. ->withErrors($validator)
  73. ->withInput();
  74. } else {
  75. $marker = Marker::find($id);
  76. $marker->name = Input::get('name');
  77. $marker->x = Input::get('x');
  78. $marker->y = Input::get('y');
  79. $marker->save();
  80.  
  81. Session::flash('message', 'Successfully updated marker!');
  82. return Redirect::to('markers');
  83. }
  84. }
  85.  
  86. public function destroy($id)
  87. {
  88. $marker = Marker::find($id);
  89. $marker->delete();
  90.  
  91. Session::flash('message', 'Successfully deleted the marker!');
  92. return Redirect::to('markers');
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement