Reputation: 103
I am new to laravel session:
here is my code to get session:
Session::set('user_id', $user);
$session_id = Session::get('user_id');
echo $session_id;exit;
Included namespaces:
use Illuminate\Http\Request;use Illuminate\Support\Facades\Session;use App\Role;use App\User;use DB;
Error is:
FatalThrowableError in Manager.php line 137: Call to undefined method Illuminate\Session\Store::set()
Thanks to all for any help.
Upvotes: 2
Views: 641
Reputation: 13259
Just adding to the solution already provided. With Laravel 5.4, you have access to global helpers so you don't have to always import classes to your controller. For sessions, you could do
session(['user_id' => 'user_id']); //or
session()->put('user_id', 'user_id');
//You retrieve like this
$session_id = session('user_id');
Upvotes: 0
Reputation: 11584
In laravel 5.4 Session::set
changed to Session::put
try
Session::put('user_id', 'user_id');
$session_id = Session::get('user_id');
dd($session_id);exit;
You'll get your session result;
Upvotes: 3