2
votes

I want to use a custom config file to access a session variable – or a fallback if not set.

But I get an HTTP ERROR 500 once i add Session::get()

[05-May-2016 19:53:16] PHP Deprecated: Non-static method Symfony\Component\HttpFoundation\Session\Session::has() should not be called statically in /Users/.../config/constants.php

What's wrong?

<?php
// File: app/config/constants.php

use Symfony\Component\HttpFoundation\Session\Session;


$something = Session::has('something') ? Session::get('something') : "fallback";


return [
    'something ' => $something
];

Update 1:

use Session;

results in this error:

Fatal error: Uncaught exception 'ReflectionException' with message 'Class log does not exist' in /Users/…/vendor/laravel/framework/src/Illuminate/Container/Container.php:738 Stack trace: #0 /Users/…/vendor/laravel/framework/src/Illuminate/Container/Container.php(738): ReflectionClass->__construct('log') #1 /Users/…/vendor/laravel/framework/src/Illuminate/Container/Container.php(633): Illuminate\Container\Container->build('log', Array) #2 /Users/…/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('log', Array) #3 /Users/…/vendor/laravel/framework/src/Illuminate/Container/Container.php(853): Illuminate\Foundation\Application->make('Psr\Log\LoggerI...') #4 /Users/…/vendor/laravel/framework/src/Illum in /Users/…/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 738

2
What do your logs say?Derek S
Try just use Session; to import the Session facade.user1669496
I've added the logs: Session::has() should not be called staticallyfabian
use Session; results in another error. See update 1.fabian

2 Answers

3
votes

You should be useing the Facade from the Illuminate\Support package.

use Illuminate\Support\Facades\Session;

Then you can correctly use Session::

0
votes

You can't access session in config file in laravel the alternative solutions is to store your session variable in a cookie and then access that cookie in config file. Use $_COOKIE php array to access cookies.