All individual subscriptions are 50% off this week only!

DanielGG
1 year ago
282
2
Laravel

RuntimeException Session store not set on request.

Posted 1 year ago by DanielGG

Hi,

I was watching episode 19 from the Laravel 5.4 From Scratch series, when I got this error at around 15 minutes. I tried to undo most of the changes I made, but the error still persists. I've been stuck on this for a while now, and I would be really thankfull if someone could help me.

Error report:

"Session store not set on request."

In vendor\laravel\framework\src\Illuminate\Http\Request.php

Code:

    public function session()
    {
        if (! $this->hasSession()) {
            throw new RuntimeException('Session store not set on request.');
        }
 
        return $this->getSession();
    }

Application frames (1)

in Illuminate\Foundation\Http\Kernel handle

code:

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

Here are some of my files. I didn't include most of the files I didn't work on for a while. Please ask for more files if needed.

web.php

<?php
Route::get('/posts/create','[email protected]');
Route::get('/posts','[email protected]')->name('home');
Route::post('/posts','[email protected]');
Route::get('/posts/{post}','[email protected]');
Route::post('/posts/{post}','[email protected]');

//Route::get('/tasks','[email protected]');
//Route::get('/tasks/{task}','[email protected]');

Route::get('/register','[email protected]');

Route::post('/register','[email protected]');

Route::get('/login','[email protected]')->name('login');
Route::get('/logout','[email protected]');

PostsController:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Post;

class PostsController extends Controller
{

    public function __construct(){

        $this->middleware('auth')->except(['index','show']);
    }

    public function index()
    {

        $posts = Post::latest()->get();


    return view('posts.index',compact('posts'));

    }

    public function show(Post $post)
    {

    return view('posts.show',compact('post'));

    }

    public function create()
    {
        return view('posts.create');
    }

    public function store()
    {

        $this->validate(request(),[
            'title'=> 'required',
            'body' => 'required'

        ]);

        Post::create(request(['title',auth()->user()->id]));



       return redirect()->home();
    }


}

CommentController

<?php

namespace App\Http\Controllers;

use App\Post;
use App\Comment;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;


class CommentController extends Controller
{
    public function store(Post $post)
    {
        $this->validate(request(),['body'=>'required|min:2|max80']);
        $post->addComment(request('body'));

        return Redirect::back();
    }
}

RegistrationController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\user;


class RegistrationController extends Controller
{

    public function create()
    {
        return view('registrations.create');
    }

    public function store()
    {

        $this->validate(request(),[
            'name'=>'required',
            'email'=>'required|email',
            'password'=>'required|confirmed'
        ]);

        $user = User::create(request(['name','email','password']));

        auth()->login($user);

        return redirect()->home();

    }

}

SessionsController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SessionsController extends Controller
{

    public function create()
    {
        return view('sessions.create');
    }


    public function destroy()
    {
        auth()->logout();

        return redirect()->home();
    }
}

Please sign in or create an account to participate in this conversation.