<?php

namespace App\Http\Middleware;

use App\Models\Admin;
use App\Traits\GeneralTrait;
use Closure;
use Str;
class AdminAuthApi
{
    use GeneralTrait;

    public function handle($request, Closure $next)
    {


//        $token = $request->header('auth-token');
//        $request->headers->set('auth-token', (string) $token, true);
//        $request->headers->set('Authorization', 'Bearer '.$token, true);

                $header = $request->header('Authorization', '');
                if (Str::startsWith($header, 'Bearer ')) {
                    $x=Str::substr($header, 7);
                }

              if(!empty($x)) {
                  $admin = Admin::where('token', $x)->first();


                  if (empty($admin)) {

                      return $this->returnErrorKey(trans('admin.Logoutt'),'auth');

                  }
              }else{


                  return $this->returnErrorKey(trans('admin.Logoutt'),'auth');
              }

        return $next($request);
    }
}
