Asked  2 Years ago    Answers:  5   Viewed   234 times

In new laravel I can't get session in constructor. Why?

public function __construct()
    dd(Session::all()); //this is empty array

and then below

public function index()
    dd(Session::all()); //here works

In old laravel i remember there was not this problem. something changed?



You can't do it by default with Laravel 5.3. But when you edit you Kernel.php and change protected $middleware = []; to the following it wil work.

protected $middleware = [

protected $middlewareGroups = [
    'web' => [

    'api' => [

Hope this works!

Wednesday, December 21, 2022

It's worth noting that Laravel actually only stores active sessions in the session folder; those that are 'remembered' but haven't been actively accessing your application do not count among these sessions. As such, just deleting the files won't finish the job.

You must also clear all Remember Tokens from the users table, as this token is used in conjunction with the local token stored in the cookie to re-create the session when a user reconnects.

Monday, September 26, 2022

In order to get remember me functionality you shouldn't work with session configuration. Instead, you should use the functionality already built into Laravel.

When you authenticate user with Auth::attempt(), you can pass a boolean value as the second argument. Set it to true, if user checked remember me checkbox. Set it to false otherwise.

This way, when checkbox is checked, user will be remembered till they manually log out of application. Otherwise, they'll be remembered till they close the browser or session expires.

You can find some more informaton here:

Thursday, October 13, 2022

Your $rr variable contains an object of class HootlexFriendshipsModelsFriendship - you can see its source code here:

As you can see, this model allows you to access both sender and recipient of given friend request via properties of the same name.

Therefore, in order to get username of the sender, you'll need to access it with:

Saturday, August 27, 2022

As you've added a new method into a resourceful controller, you should register the new method first, before the resource.


<?php // Routes.php

Route::get('/admin/login', '[email protected]');
Route::resource('admin', 'AdminController');

This way your before filters should work as you have then like this:

<?php // AdminController.php
   class AdminController extends BaseController {
     function __construct() {
       $this->beforeFilter('admin', array('except' => array('adminLogin')));
      $this->beforeFilter('csrf', array('on' => 'post'));
Sunday, December 4, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :

Browse Other Code Languages