在查询行上给出控制器错误。拉维尔

发布于 2025-01-13 12:44:00 字数 519 浏览 0 评论 0原文

这是我的控制器的代码,我在其中使用查询从表“用户”中查找来自表单的电子邮件地址的电子邮件地址。但它在查询行“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;        

    }   
}

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;        

    }   
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

喵星人汪星人 2025-01-20 12:44:00

为什么要使用 $request->input() ?要成功创建登录功能,您可以尝试通过雄辩的功能登录,

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.');   
}

这将检查用户的电子邮件地址是否有效,如果凭据不正确,它将返回这些凭据不存在的错误匹配。

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.

清旖 2025-01-20 12:44:00

导入正确的类 use App\Models\user; 而不是 use App\Models\usern;

并且类名的首字母应该大写。

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

and first letter of class name should be uppercase.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文