<?php

namespace App\Http\Middleware;

use Closure;
use App\Models\User;

class CsrfLoginDev
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        // dd('ddd')
        // auth()->loginUsingId(User::where('username', 'witel')->first()->id);
        // // dd(csrf_token());
        // // $request->headers->set('X-CSRF-TOKEN', csrf_token());
        // // dd($request->headers);
        // $handle = $next($request->request->add(['_token' => csrf_token()]));
        // // $handle->header('X-CSRF-TOKEN', csrf_token());
        // // if(method_exists($handle, 'header'))
        // // {
        // //     $handle->header('Access-Control-Allow-Origin' , '*')
        // //         ->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
        // //         ->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Application');
        // // }
        // return $handle;
        // return $next($request)->header('X-CSRF-TOKEN', csrf_token());
        // dd($request->secure());
        dd(url()->current());
        // if (!$request->secure()) {
        //     dd(1);
            return redirect()->secure($request->getRequestUri());
        //  }

         return $next($request); 
    }
}
