Payload

The payload can contain any data you want to send to the frontend for possible further processing in JavaScript.
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();
    }
}

Example

  • Only usernames that contain a number are available.

    Payload Data

    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.

Github