<?php

namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

use Closure;

class MiddlewareAdministrador
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //return $next($request);
        /*if(Auth::check() && Auth::user()->user_tipe == 'Admin')
        {
            return $next($request);
        }
        
        abort(403);*/

        switch(Auth::user()->user_tipe)
        {
            case('Admin'):
                return $next($request);
            break;
            case('RRHH'):
                abort(403);
            break;
            case('Bodega'):
                abort(403);
            break;
            case('Capataz'):
                abort(403);
            break;
            case('Gral'):
                abort(403);
                //return redirect()->back()->with('error', "Access error, you do not have access to \"$friendly_name\".");
            break;
        }
    }
}
