Laravel 生产中的应用程序不会在 Chrome、Safari 和 Edge 中登录,但会在 Firefox 中登录

Laravel Application in production don't login in Chrome, Safari and Edge but does in Firefox

我使用 Laravel 8 部署了一个 Laravel 应用程序(正在生产中),但是,当我使用 Chrome、Safari、Edge 登录时,显示错误 419。但在 Firefox 中不显示。我找到了其他答案,每个人都说“检查 csrf”,但是,表格有它。

这里是登录表单

<form method="POST" action="{{ route('login') }}">
                @csrf
              <div class="input-group mb-3">
                <input placeholder="Correo electrónico" id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>               
                <div class="input-group-append">
                  <div class="input-group-text">
                    <span class="fas fa-envelope"></span>
                  </div>
                </div>
                @error('email')
                    <span class="invalid-feedback" role="alert">
                        <strong>{{ $message }}</strong>
                    </span>
                 @enderror
              </div>
              <div class="input-group mb-3">
                <input placeholder="Contraseña" id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="current-password">                
                <div class="input-group-append">
                  <div class="input-group-text">
                    <span class="fas fa-lock"></span>
                  </div>
                </div>
                @error('password')
                    <span class="invalid-feedback" role="alert">
                        <strong>{{ $message }}</strong>
                    </span>
                @enderror
              </div>
              <div class="row">
                <div class="col-8">
                  <div class="icheck-primary">
                    <input type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
                    <label for="remember">
                      Recuérdame
                    </label>
                  </div>
                </div>
                <!-- /.col -->
                <div class="col-4">
                  <button type="submit" class="btn btn-primary btn-block">{{ __('Entrar') }}</button>
                </div>
                <!-- /.col -->
              </div>                  
            </form>

和 .env 文件

APP_NAME=theproyect
APP_ENV=local
APP_KEY=base64:1ZRWjL3Of6m57zKh5sUvfUkW2kzo5vIjOmttnp0dboE=
APP_DEBUG=false
APP_URL=http://mydomian

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=thedatabase
DB_USERNAME=theuser
DB_PASSWORD=thepassword

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

和 config/session.php 文件

<?php

use Illuminate\Support\Str;

return [

   
    'driver' => env('SESSION_DRIVER', 'file'),

    'lifetime' => env('SESSION_LIFETIME', 120),

    'expire_on_close' => false,

    'encrypt' => false,

    'files' => storage_path('framework/sessions'),

    'connection' => env('SESSION_CONNECTION', null),

    'table' => 'sessions',

    'store' => env('SESSION_STORE', null),


    'lottery' => [2, 100],

  
    'cookie' => env(
        'SESSION_COOKIE',
        Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
    ),


    'path' => '/',

    'domain' => env('SESSION_DOMAIN', null),


    'secure' => env('SESSION_SECURE_COOKIE'),


    'http_only' => true,

    'same_site' => 'lax',

];

确保您对 storage:

有适当的权限
chmod -R 755 storage

如果这不起作用,请考虑清除缓存。应用程序缓存也可能导致会话过期错误。这也可以用于浏览器缓存。您可以像这样清除缓存:

php artisan cache:clear

请注意,

This will clear all the cache data in storage.

让我知道这是否有效。

这是因为 HTML 标记缺少结束 /> 标记,因此无效:

<input placeholder="Correo electrónico" id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>

任何 IDE 都应将此行显示为红色 ...