php - Laravel redirect route with id variable won't work -
i have made update function laravel 4.2 website work. updates table in database right infomation when want redirect same view came problem.
the url shows:
http://localhost:8000/admin/page/%7bpageid%7d
when schould say:
http://localhost:8000/admin/page/1
here link image showing error in browser:
http://i.imgur.com/ggo5elg.png
this view ( admin.pages )
@section('content') <div class='box box-info'> <form method="post" action="/admin/page/{{$page->id}}"> <div class='box-header'> <div class='box-body pad'> <input type="text" name="title" value="{{$page->title}}" class="form-control"> </div> </div> <div class='box-body pad'> <textarea id="editor1" name="text" rows="2" cols="80"> {{ $page->text }} </textarea> <br> <input type="submit" class="btn btn-primary" value="opdater"> </div> </form> </div> @stop
this controller ( pagecontroller ) have redirect in update function.
<?php class pagecontroller extends basecontroller { public function index($pageid) { $data['pageid'] = $pageid; $page = page::find($pageid); return view::make('admin.pages', $data) ->with(compact('page')); } public function update($pageid) { db::table('pages') ->where('id', $pageid) ->update(array( 'title' => input::get('title'), 'text' => input::get('text'))); return redirect::route('page')->with('succes', 'du har sendt en besked'); } }
this 2 routes use in case
route::get('/admin/page/{pageid}', array('as'=>'page', 'uses'=>'pagecontroller@index')); route::post('/admin/page/{pageid}', array('as'=>'page', 'uses'=>'pagecontroller@update'));
if need anymore information let me know.
the page
route requires parameter named {pageid}
, , need pass when redirecting:
return redirect::route('page', ['pageid' => $pageid])->with('succes', 'du har sendt en besked');
you can read more in laravel redirects documentation.
Comments
Post a Comment