Support the ongoing development of Laravel.io →
posted 9 years ago
Session

This is my code:

<?php
namespace App\Users;

use Illuminate\Support\Facades\Session;

class Mapper
{
    public function areValidCredentials($username, $password)
    {
        $result = User::find(['username' => $username])->fetch('password');

        if(password_verify($password, $result)) {
            return true;
        }
        return false;
    }

    public function createSession($username)
    {
        Session::put('username', $username);
    }
}

But, it says me this: method 'put' not found in the class 'Illuminate\Support\Facades\Session'

Last updated 3 years ago.
0

instead of use Illuminate\Support\Facades\Session; add use Session

0

Use the Session class in the root namespace.

I.e.

public function createSession($username)
{
    \Session::put('username', $username); // Note the backslash to indicate the root class path.
}

The use Session; method should also work.

If this still doesn't work you can use the session() helper function which returns a session instance:

public function createSession($username)
{
   session()->put('username', $username);

   var_dump( session()->get('username') ); // outputs the value of $username
}
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.