I'm just going to throw this into a controller, which might not be a good idea in the context of your app. Just doing it for the sake of brevity and to get the point across. Same thing for Facades.
public function index()
{
if ($name = Input::get('name')) return Redirect::route('home')->withName($name);
return View::make('home');
}
Or redirect to an action or whatever you need.
Laravel will flash that into the session, so you can retrieve that via Session::get('name').
public function index()
{
if( Input::has('name') )
{
$name = Input::get('name');
// Store the name to the session
Session::put('name', $name);
// You can just pass it to the view, without storing it.
return Redirect::route('home')->withName($name);
}
return View::make('home');
}
@RachidLaasri No need to use Session::put. Laravel does it when you use ->with alongside Redirect. That won't pass it to the view, you won't be able to do {{ $name }}. Instead you'll retrieve the data using Session::get('name').
function __construct( Request $request)
{
$this->request = $request;
}
public function yourMethodName()
{
// get the request session store which will include the uri
$session = $this->request->session(1);
// check in the session store for name or whatever value you want
if(in_array( 'name', (array) $session))
{
return redirect();
};
}