如何使用laravel 5.4进行验证 [英] How to auth with laravel 5.4
问题描述
如果我的auth表名只是用户,有些错误是可以避免的,即使现在我也是改为用户,我仍然卡住了。
我尝试过的事情:
我最终通过删除此行登录了某个点
$ this-> middleware('auth') ;
来自
HomeController
构造函数的然后手动设置我自己的身份验证,就像我在30分钟内完成的那样,如果我从头开始。但它感到做作。教程说一切都应该开箱即用而不触及任何本机PHP函数,所以我取消注释了行并继续扭动。
目前的情况是登录表单只是即使我已经手动播种了我的数据库。从
web.php
文件(据我所知是neo routes.php),我有 Route :: post('/ login','HomeController @ loginPost');
然后在其控制器中,我试过的最新片段是这个
公共函数loginPost(){
var_dump(Input :: all());
if (Auth :: attempt(Input :: all())){
var_dump( ' expression');
User :: create([
' username' => strtolower( Input :: get(' username')),
' password' => Hash :: make(输入:: get('' 密码')),
]);
$ user = User :: where(' 用户名,' =',strtolower(输入::获取(' username')));
Auth :: login($ user);
}
else var_dump(' 表达式2' 跨度>);
}
它可能应该是那里的电子邮件而不是用户名但是我在视图中替换了所有内容,因为应用程序的身份验证ID应该交换用户名的电子邮件是他们的用户名而不是他们的电子邮件。当我立即按Enter键时,页面只会重新加载空输入字段。它甚至厌倦了向我抛出错误。有没有出路或Laravel不适合我?
this-> middleware('auth');
来自HomeController
构造函数,然后手动设置我自己的auth,就像我从头开始开发30分钟一样。但它感到做作。教程说一切都应该开箱即用而不触及任何本机PHP函数,所以我取消注释了行并继续扭动。
目前的情况是登录表单只是即使我已经手动播种了我的数据库。从web.php
文件(据我所知是neo routes.php),我有
Route :: post('/ login','HomeController @ loginPost');
然后在其控制器中,我试过的最新片段是这个
公共函数loginPost(){
var_dump(Input :: all());
if (Auth :: attempt(Input :: all())){
var_dump( ' expression');
User :: create([
' username' => strtolower( Input :: get(' username')),
' password' => Hash :: make(输入:: get('' 密码')),
]);
user = User :: where( ' 用户名',' =',strtolower(输入:: get(' 用户名')));
Auth :: login(
user);
}
else var_dump(' 表达式2' 跨度>);
}
它可能应该是那里的电子邮件而不是用户名但是我在视图中替换了所有内容,因为应用程序的身份验证ID应该交换用户名的电子邮件是他们的用户名而不是他们的电子邮件。当我立即按Enter键时,页面只会重新加载空输入字段。它甚至厌倦了向我抛出错误。有没有出路或Laravel不适合我?
Hey there. I am unable to get anything to work because of the thousands of micro PHP classes scattered across another thousand folders created by Laravel. 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 Authentication - Laravel - The PHP Framework For Web Artisans[^] and stackoverflow questions with outdated answers to the cryptic errors I've been riddled with. This has been on for the past 7 days.
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.
What I have tried:
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 30 mins 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', 'HomeController@loginPost');
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?
this->middleware('auth');
from theHomeController
constructor then manually setting up my own auth like I would have done in 30 mins 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 theweb.php
file (which I understand is neo routes.php), I have
Route::post('/login', 'HomeController@loginPost');
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?
这篇关于如何使用laravel 5.4进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!