nmeri17
2 years ago
134
37
Laravel

How to auth with Laravel 5.4

Posted 2 years ago by nmeri17

I keep getting all sorts of funny errors just by trying to see an application can actually work in Laravel and that it's not a myth. First, I had to wrestle with all the suggestion on this issue. Painfully, the answer that helped me was the penultimate on such a long long thread of framework contributors living in denial. I've encountered dozens more, scoured tutorial sites, read this official doc on Laravel auth and stackoverflow questions with outdated answers to the cryptic errors I've been riddled with.

Some of the errors would have been avoidable if my auth table name was simply "users" and even now I've changed to "users", I'm still stuck.

I eventually logged in at some point by removing this line

$this->middleware('auth');

from the HomeController constructor then manually setting up my own auth like I would have done in 30mins if I was developing from scratch. But it felt contrived. The tutorials say everything should work out of the box without touching any native PHP functions so I uncommented the line and continued writhing.

The present situation is that the login form just lies there even though I've manually seeded my database. From the web.php file (which I understand is neo routes.php), I have

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

Then in its controller, the latest snippet I've tried is this

public function loginPost() {
        var_dump(Input::all());
        if (Auth::attempt(Input::all())) {
            var_dump('expression');
        User::create([
        'username' => strtolower(Input::get('username')),
        'password' => Hash::make(Input::get('password')),
        ]);

$user = User::where('username', '=', strtolower(Input::get('username')));

Auth::login($user);
        }
        else var_dump('expression2');
    }

It's probably supposed to be email there instead of username but I did a replace all in the view, swapping email for username since the application's authentication ID should be their usernames and not their emails. When I hit enter now, the page just reloads with empty input fields. It's even tired of throwing errors at me. Is there a way out or is Laravel just not for me?

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