namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UsersController extends Controller
{
private $response;
public function __construct(AsyncResponse $response)
{
$this->response = $response;
}
public function checkUsername(Request $request)
{
...
$this->response->setPayload([
'username' => $username,
'status' => $status,
'message' => ' ... ',
]);
return $this->response->send();
}
}
In this example, we use payload to verify the availability of username.
Using the AsyncRequest method, we found out the availability status which was verified by the backend.