<?php

namespace App\Http\Middleware;

use Closure;
use App\Option;

class BlockId
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if($request->route()->hasParameter('id')) {
            $block_movie = Option::getSetting('block_movie');
            $block_tv = Option::getSetting('block_tv');
            $block = array_merge($block_movie, $block_tv);
            $id = $request->route()->parameter('id');

            if (in_array($id, $block)) {
                return redirect()->route('home');
            }
        }

        return $next($request);
    }
}
