Support the ongoing development of Laravel.io →
Session Architecture
Last updated 1 year ago.
0

No, there is no Session Contract available yet. ##If you want to resolve a Session Store Using Ioc Container When we use Session Facade proxy it returns an instance of a SessionManager class which dynamically calls the methods on the underlying Session Store. If we take a look at the Session Store class we can see that it implements the Illuminate\Session\SessionInterface which is actually extended from the Symfony\Component\HttpFoundation\Session\SessionInterface. So, if you want to resolve a Store instance through IoC container you can inject a dependency like this:

use Symfony\Component\HttpFoundation\Session\SessionInterface as SessionContract;

Route::get('/session',function(SessionContract $session) // Injection using type hinting.
{
	//example put call on Store.
	$session->put('name','usman');

	//getting the stored value.
	return $session->get('name');
});

Of course you can use a similar approach with Controller actions. Regards,

Last updated 1 year ago.
0

it is safer to use

HttpFoundation/Session/SessionInterface

which extends the symfony interface

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

keevitaja keevitaja Joined 2 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.