我使用默认的Laravel Autentification。但是由于某种原因,它以某种方式崩溃了。 当我尝试登录或注册时,如果auth成功,它将进行重定向,请尝试将我重定向到正确的链接,但同时将我返回到/ login。
尝试身份验证后的调试栏
1。我的路线:
Auth::routes();
Route::get('/confirm', function () {
return view('confirm');
})->name('confirm');
Route::post('/confirm', 'EmployeeController@store')->name('addworker');
Route::get('users/{id}', 'EmployeeController@show')->where('id', '[0-9]+')->name('account');
Route::get('/home', 'HomeController@index')->name('home');
2。更改为登录和注册控制器:
protected function redirectTo()
{
return route('account',['id'=> auth()->user()->id]);
}
3.EmployeeController中的方法,在auth中执行该操作:
public function __construct()
{
$this->middleware('auth');
$this->middleware('confirmated');
}
public function show($id)
{
return view('account');
}
4。我的中间件:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use App\Employee;
class CheckConfirm
{
public function handle($request, Closure $next)
{
if (Auth::check()) {
$id = Auth::id();
$empl = Employee::where('user_id', '=', $id)->first();
Debugbar::info($empl);
if ($empl == null) {
return redirect()->route('confirm');
} else {
dump($empl);
return $next($request);
}
} else {
return redirect()->route('login');
}
}
}
cache:clear
和config:clean
如果问题中没有足够的信息,您可以在GitHub上下载我的整个项目:https://github.com/Vladislav2018/last.chance/