Home > Enterprise >  Giving controller error on query line. Laravel
Giving controller error on query line. Laravel

Time:03-12

This is my controller's code, where i am using a query to find an email address from the table "user" against an email address that comes from a form. But it gives the error on the query's line "App\Http\Controllers\user".

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\usern;
use App\Models\post;
use Illuminate\Support\Facades\DB;



class homeController extends Controller{
    public function userLogin(Request $request) {

        $data= $request->input();

        $userEmail= user::where('Email',$request->email)->first; 
        echo $userEmail;        

    }   
}

CodePudding user response:

Why you're using $request->input() ? What you can do to successfully create a login function is by attempting to log in through eloquent function

public function login(Request $request){
        $validate = $this->validate($request, [
            'email'     => 'required|email|max:255',
            'password'  => 'required|min:5',
        ]);
        $credentials = $request->only('email', 'password');

        if (Auth::guard('admin')->attempt($credentials)) {
            $session = $request->session()->regenerate();
            return Redirect::route('admin.dashboard')->with('success','Login success.');
        }
        return back()->with('error','The provided credentials do not match our records.');   
}

This will check if the user's email address is valid or not and if the credentials are not correct it'll return back with error that these credentials don't match.

CodePudding user response:

Import correct class use App\Models\user; not use App\Models\usern;

and first letter of class name should be uppercase.

  • Related