How can I set a global session in Laravel. In a normal PHP-script a global session like $_SESSION['myvar'] dies if the browser is closed or the function session_destroy()/unset() is called.
I tried this in Laravel, but it does not work in a controller extends BaseController:
Session::set( 'id', $user->id );
Session::get( 'id' );
The Context of my code is:
// ROUTES
Route::get( '/', 'MyController@setSession' );
// CONTROLLER
class MyController extends Controller
{
public function setSession( )
{
// ...
Session::set( 'id', $user->id );
return view('access');
}
}
// VIEW -> LOST Session
@if (Session::has('id') && Session::get('id') == 'hsdiwe78912hj')
I have access!
@else
I must stay here! <!-- I always get this -->
@endif
use
Session::put('id', $user->id );
Session::get('id' );
Session::forget('id' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With