ayazio's avatar

Lost trying to implement Authentication

Hi guys,

Complete noob to Laravel and Lumen here. I'm trying to create a simple username/password login system. I have read Laravel and Lumen documentation have been at it for like 6 hours now but I just can't figure it out. You have no idea how stupid I feel right now. Is Laravel better suited for this type of thing or something? Googling and searching on these boards got me nowhere either. I don't really understand the relationship between the AuthServiceProvider and this AuthManager class or how this all fits together.

Here is my LoginController.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    public function authenticate(Request $request) {

        $credentials = $request->only('email', 'password');

        if (Auth::attempt($credentials)) {
            return ['result' => 'ok'];
        }
    }

    public function LoginPage() {
        return view("admin.login");
    }

    //
}

and this is where that gets me.

FatalThrowableError in AuthManager.php line 294:
Call to undefined method Illuminate\Auth\RequestGuard::attempt()
0 likes
6 replies
Snapey's avatar

well which is it, Laravel or Lumen?

ayazio's avatar

Lumen. Sorry I didn't specify.

By the way, Service Provider and Middleware are uncommented in app.php

Snapey's avatar

The thing is, Lumen is really designed for fast api based services. From the docs;

Authentication in Lumen, while using the same underlying libraries as Laravel, is configured quite differently from the full Laravel framework. Since Lumen does not support session state, incoming requests that you wish to authenticate must be authenticated via a stateless mechanism such as API tokens.

assuming you know this, and this is the way you will be using it then study the docs regarding how to achieve what you want

ayazio's avatar

So it is better to use Laravel then? Is Lumen supposed to be used only with APIs? I chose Lumen for this because it's a very simple CRUD app. Thought Laravel would be too heavy for something as simple as this.

ejdelmonico's avatar

You can study the docs like @snapey advised and search on the web for token usage in Lumen or Laravel. You should find your answer when you are fully informed. Choosing between the two is decided by how much speed you really need since Laravel is pretty fast with PHP 7.

Please or to participate in this conversation.