public function sign(Request $request, $id) { $delivery = Delivery::find($id); if (!$delivery || $delivery->state == 0) { return Response::json("Error", 400); } else { //Okay, let's check if the the current logged agent $userId = Authorizer::getResourceOwnerId(); $agent = Agent::where('user_id', $userId)->first(); if (!$agent) { return Response::json("Error", 400); } if ($delivery->agent_id != $agent->id) { return Response::json("Error", 403); } $file = $request->file('signature'); if ($file !== null) { if ($file->isValid()) { $file->move(public_path() . "/uploads", $id . "_signature.png"); return Response::json("OK", 200); } } } return Response::json("Error", 400); }