<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class CheckCustomSessionData
{
    /**
     * Handle an incoming request.
     *
     * @since 1.0.0
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     *
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if ((! session()->has('timezone_name') || empty(session('timezone_name'))) && $request->user()) {
            session()->put('timezone_name', $request->user()->timezone_name);
        }

        return $next($request);
    }
}
