<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Artisan;

class ClearCache {
    /** @var Application */
    private $application;

    /**
     * @param Application $application
     */
    public function __construct(Application $application) {
        $this->application = $application;
    }

    /**
     * @param         $request
     * @param Closure $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next) {
        // only run view:clear if we're not on production
        if ($this->application->environment() !== 'production') {
            Artisan::call('view:clear');
        }

        return $next($request);
    }
}
