Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Http\Requests;
- use App\Http\Controllers\Controller;
- use App\Marker;
- class MarkerController extends Controller
- {
- public function index()
- {
- $markers = Marker::all();
- return view('markers.index', ['markers' => $markers]);
- }
- public function create()
- {
- return view('markers.create');
- }
- public function store(Request $request)
- {
- $rules = array(
- 'name' => 'required',
- 'x' => 'required|numeric',
- 'y' => 'required|numeric'
- );
- $validator = Validator::make(Input::all(), $rules);
- if ($validator->fails()) {
- return Redirect::to('markers/create')
- ->withErrors($validator)
- ->withInput();
- } else {
- $marker = new Marker;
- $marker->name = Input::get('name');
- $marker->x = Input::get('x');
- $marker->y = Input::get('y');
- $marker->save();
- Session::flash('message', 'Successfully created marker!');
- return Redirect::to('markers');
- }
- }
- public function show($id)
- {
- $marker = Marker::find($id);
- return view('markers.show', compact('marker'));
- }
- public function edit($id)
- {
- $marker = Marker::find($id);
- return view('markers.edit', compact('marker'));
- }
- public function update(Request $request, $id)
- {
- $rules = array(
- 'name' => 'required',
- 'x' => 'required|numeric',
- 'y' => 'required|numeric'
- );
- $validator = Validator::make(Input::all(), $rules);
- if ($validator->fails()) {
- return Redirect::to('markers/' . $id . '/edit')
- ->withErrors($validator)
- ->withInput();
- } else {
- $marker = Marker::find($id);
- $marker->name = Input::get('name');
- $marker->x = Input::get('x');
- $marker->y = Input::get('y');
- $marker->save();
- Session::flash('message', 'Successfully updated marker!');
- return Redirect::to('markers');
- }
- }
- public function destroy($id)
- {
- $marker = Marker::find($id);
- $marker->delete();
- Session::flash('message', 'Successfully deleted the marker!');
- return Redirect::to('markers');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement