<?php


namespace App\Http\Middleware;

class checkReseller
{
	public function handle($request, \Closure $next)
	{
		$token = $request->token;
		$reseller = \App\Reseller::where('token', $token)->first();

		if ($reseller) {
			$expire_time = strtotime($reseller->end_at);
			if (($expire_time < time()) || !$reseller->status) {
				return response()->json(['status' => 'error', 'message' => 'Expired Token']);
			}
		}
		else {
			return response()->json(['status' => 'error', 'message' => 'Invalid token']);
		}

		return $next($request);
	}
}

?>