LaravelのSSL化対策

環境
- Laravel >= 5.5
常時SSL化
LaravelはAPP_URL
をhttpsにしてもasset()
やroute()
などはhttpsにならずhttpのままなため、App/Providers/AppServiceProvider.php
に以下を追記する必要がある。
<?php
namespace App\Providers;
use Illuminate\Routing\UrlGenerator;
class AppServiceProvider extends ServiceProvider
{
public function boot(UrlGenerator $url)
{
$url->forceScheme('https');
}
}
Cookieにsecure属性を付与する
Cookieにsecure属性を付与するために.env
ファイルでSESSION_SECURE_COOKIE
を true
に設定します。
SESSION_SECURE_COOKIE=true