<?php

namespace App\Http\Middleware;

use Closure;
use Gloudemans\Shoppingcart\Facades\Cart;
use Illuminate\Http\Request;

class CheckCart{
    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next){
        if (auth()->check() && Cart::instance('default')->count() > 0) {
            return $next($request);
        }
        return redirect()
              ->route('shop.index')->with([
                  "message" => __("Your cart is empty. Please add products and continue."),
                  "alert-type" => "danger",
            ]);
    }
}
