<?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('thing') || empty(session('thing'))) && $request->user()) {
            session()->put('thing', $request->user()->thing);
        }

        return $next($request);
    }
}
