A
A
Alexey Ivanov2018-07-04 00:23:42
Sessions
Alexey Ivanov, 2018-07-04 00:23:42

Why session is not saved in Laravel 5.6?

Hello!
Friends, please help...
I've been studying Laravel for a couple of weeks, installed 5.6, little by little I'm testing routers, controllers, midlers, providers)) Things were moving slowly, but I was in no hurry to delve into the very structure of the framework. And today, almost out of the blue (I didn’t poke around in the engine folder, I didn’t change any global settings), problems started: when sending a post-request, the page “The page has expired due to inactivity. Please refresh and try again” pops up, when an attempt to authenticate through the standard Auth gives the same thing, it does not work to log in. Although until the last moment everything was fine - I sent data from the form more than once, they were perfectly validated, displayed through dump (), I passed authentication without any problems, authorized in a closed section, in short, everything is like in the manual. And here on you...
At first, I even started to sin on assembling the server (I have openServer on Windows), transferred the project to shared hosting, the result is exactly the same.
I noticed that the server does not save sessions. That is, by executing the following code in the controller:

session(['key' => 'value']);
        $request->session()->push('key2', 'value2');
        dump(Session::all());

session data is displayed, but the next page reload is not added. If you comment out the first two lines, then after the next reboot, the key and key2 variables disappear. And each time a new one issues a token. Here is the page where you can see it: click . I checked and double-checked all the config files just in case, the attributes for the storage/ folder are set to 777. Of course, the "@csrf" construction is present where it should be - everything worked without problems before.
For example,
the web.php code:
<?php
Route::get('/', function () {
    return view('welcome');
});
Route::get('/about',['uses'=>'Admin\[email protected]','as'=>'about']);
Route::get('/articles',['uses'=>'Admin\[email protected]','as'=>'articles']);
Route::get('/article/{id}',['uses'=>'Admin\[email protected]','as'=>'article']);
Route::get('/contact',['middleware' => ['web'],'uses'=>'Admin\[email protected]','as'=>'contact']);
Route::post('/contact',['middleware' => ['web'],'uses'=>'Admin\[email protected]','as'=>'contactP']);
Route::get('/home', ['middleware' => 'auth','uses' =>'[email protected]', 'as' => 'home']);

//Route::group(['middleware' => 'web'], function () {
    //Auth::routes();
//});

Route::group(['prefix' => 'admin', 'middleware' => ['web','auth']], function () {
    Auth::routes();
    Route::get('/', ['uses' => 'Admin\[email protected]', 'as' => 'admin_index']);
    Route::get('/add/post',['uses'=>'Admin\[email protected]','as'=>'admin_add_post']);
    Route::post('/add/post',['uses'=>'Admin\[email protected]','as'=>'admin_add_post_p']);
    Route::get('/update/post/{id}',['uses'=>'Admin\[email protected]','as'=>'admin_add_post']);
    Route::post('/update/post',['uses'=>'Admin\[email protected]','as'=>'admin_update_post_p']);
});
Route::group(['middleware' => ['web']], function () {
    Route::get('/login', ['uses' => 'Auth\[email protected]', 'as' => 'login']);
    Route::post('/login', ['uses' => 'Auth\[email protected]', 'as' => 'login_post']);
});

Controller Admin\ContactController :
<?php
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Session;

class ContactController extends Controller
{
    public function store(Request $request, $id=FALSE) {    
        return redirect()->route('contact');
  }	
  public function show(Request $request) {
        session(['key' => 'value']);
        $request->session()->push('teams', 'developers');
        dump(Session::all());
    return view('default.contact',['title'=>'Contacts']);
  }   
}

Contact.blade.php file code:
@extends('default.layouts.layout')
@section('content')
<div class="col-md-9">
  <div class="">
    <h2>Contact us!</h2>
    </div>
  @if ($errors->any())
    <div class="alert alert-danger">
      <ul>
        @foreach ($errors->all() as $error)
          <li>{{ $error }}</li>
        @endforeach
      </ul>
    </div>
  @endif
  <p>
  This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.
  </p>

  <form method="post" action="{{ route('contact') }}">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <div class="form-group">
      <label for="name">Name</label>
      <input type="text" class="form-control" id="name" name="name" value="{{ old('name') }}" placeholder="Jane Doe">
    </div>
    <div class="form-group">
      <label for="email">Email address</label>
      <input type="email" class="form-control" id="email" value="{{ old('email') }}" name="email" placeholder="Email">
    </div>
    <div class="form-group">
      <label for="site">Site</label>
      <input type="text" class="form-control" id="site" value="{{ old('site') }}" name="site" placeholder="Site">
    </div>
    <div class="form-group">
      <label for="text">Text</label>
      <textarea class="form-control" id="text" name="text" rows="3">{{ old('text') }}</textarea>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>
</div>	
@endsection

Help, please, with advice - what kind of opportunity could happen? I've been digging the ground with my nose since five o'clock (((
I can throw off FTP access ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor, 2018-07-04
@v_decadence

Try not to use the output (dump) in the controller, the headers may not be sent because of this, or the request processing logic is violated. There is definitely such a problem when using dd.

K
Konstantin B., 2018-08-22
@ Kostik_1993

And what do you have in your configs, not array for an hour?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question