How does Dingo/Api return a custom status code when it is successful?

how does Dingo/Api return a custom status code in a successful state?

recently, a new version of API, has introduced Dingo/api, into laravel. Due to business needs, when you successfully return data, you can also bring status code and prompt message . The structure is as follows:

{
    status_code: 200,
    msg: "success",
    data:[...],
    ...
}

its practical laravel response ()-> json () can also be mixed, but I still want to use the feature of Dingo/api when returning the result, and can add other data, please guide the students who have practiced it.

Apr.01,2021

just use the setStatusCode method

response ()-> json ()-> setStatusCode


refer to exception handling:
if you customize exception handling:
https://laravel-china.org/doc.
setting status value is relatively simple

$result = [
        'captcha_key' => $cache_key,
        'captcha_content' => $captcha->inline(),
        'captcha_expire_at' => $expired_at,
        'code' => $code
    ];

    return $this->response->array($result)->setStatusCode(201);
    
reference link: [Dingo API 2.0.0 Chinese documentation] [1]
Menu