在查询行上给出控制器错误。拉维尔
这是我的控制器的代码,我在其中使用查询从表“用户”中查找来自表单的电子邮件地址的电子邮件地址。但它在查询行“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要使用
$request->input()
?要成功创建登录功能,您可以尝试通过雄辩的功能登录,这将检查用户的电子邮件地址是否有效,如果凭据不正确,它将返回这些凭据不存在的错误匹配。
Why you're using
$request->input()
? What you can do to successfully create a login function is by attempting to log in through eloquent functionThis 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.
导入正确的类
use App\Models\user;
而不是use App\Models\usern;
并且类名的首字母应该大写。
Import correct class
use App\Models\user;
notuse App\Models\usern;
and first letter of class name should be uppercase.