php - How to pass a value from one controller to another controller in laravel -
i struggling passing variable 1 controller method in laravel.
when user creates product, want let him result.
problem after create method executed, message should passed 1 more controller before goes view.
i trying pass success or failure message postcreate method getlist method.
create method:
public function postcreate() { if(validation passes){ //create product return redirect::to('admin/products/list/'.$current_section_id) ->with('message', 'new product created'); } else{ return redirect::to('admin/products/new) ->with('message', 'something went wrong'); } }
getlist method returns user page before (current_section_id) , list products
public function getlist($id){ $message = input::get('message'); return view::make('products.list') ->with('current_section_id', $id) ->with('message', $message); }
i have tried use ->with('message', $message);
pass message not work works forms in views.
what right way ?
using with() on view adds data passed view within same http request. however, you're doing redirect , creating new request, , with() operates differently.
to pass data between http requests need either attach url (probably not idea) or store in session (much better), laravel's session handling supports neatly, allowing flash data, place in session next http request (which with() on redirect you), , takes care of cleaning out).
you can see more in laravel documentation. however, means should go looking data in session array, rather expecting injected view automatically.
Comments
Post a Comment