我尝试使用laravel创建一个应用程序,当我在输入数据库中包含的信息后创建登录页面时,我有这个错误:
下面是登录控制器代码:
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use illuminate\Session\Middleware\StartSession;
class AuthController extends Controller
{
public function login(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required',
]);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
$user = User::getByEmail($request->email);
if ($user && Hash::check($request->password, $user->password)) {
Auth::login($user);
return redirect()->intended('/home');
} else {
return redirect()->back()->withErrors(['email' => 'The provided credentials do not match our records.'])->withInput();
}
}
}
这里是我web.php
:
use Illuminate\Auth\Events\Login;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\Auth\LoginController;
use Illuminate\Support\Facades\DB;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
Route::get('/', function () {
return view('welcome');
});
Route::group(['middleware' => ['web']], function () {
Route::get('/login', function () {
return view('login');
});
});
Session::start();
Route::post('/login', [App\Http\Controllers\AuthController::class, 'login'])->name('login');
Route::get('/client_items', 'App\Http\Controllers\ClientController@showClientItems')->middleware('auth');
Route::get('/listeitems/{siteId}/{operatorId}', 'ItemController@getItemsBySiteAndOperator');
Route::get('/hors-ligne', function () {
$pdo = DB::connection()->getPdo();
$stmt = $pdo->query('SELECT * FROM item');
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
return view('hors-ligne', ['rows' => $rows]);
});
我什么都试过了,我已经坚持了7天了
编辑:
这是我kernel.php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
];
/**
* The application's route middleware groups.
*
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
],
'api-session' =>[
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
]
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
}
和错误:
1条答案
按热度按时间ie3xauqp1#
这里是我的内核. php
命名空间应用\Http;
使用Illuminate\Foundation\Http\Kernel作为Http内核;
class Kernel extends HttpKernel { /应用程序的全局HTTP中间件堆栈。 * 这些中间件在对应用程序的每个请求期间运行。 * @var array〈int,class-string|string〉/ protected $middleware = [ // \应用程序\Http\中间件\信任主机::类,\应用程序\Http\中间件\信任代理::类,\说明\Http\中间件\HandleCors::类,\应用程序\Http\中间件\维护期间防止请求::类,\说明\基础\Http\中间件\验证后大小::类,\应用程序\Http\中间件\修剪字符串::类,\说明\基础\Http\中间件\验证Csrf令牌::类,\说明\基础\Http\中间件\将空字符串转换为空::类,\说明\会话\中间件\启动会话::类,\说明\查看\中间件\共享错误来自会话::类,];
}和错误:enter image description here