Respond
The responder class is designed to provide answers to requests.
use App\Respond;
This class is primarily used in executable controller callbacks, where it provides methods for sending responses to requests.
use Admin\Respond;
use App\Admin\Controllers\Controller;
class ShopController extends Controller
{
public function sayHelloEvent(Respond $respond): void
{
$respond->toast_success('Hello');
}
}
Respond supports the following methods:
location
Redirects to the specified address.
$respond->location(string $url)
redirect
Redirects to the specified address and reloads the page.
$respond->redirect(string $url)
reload
Reloads content on the page.
$respond->reload()
reboot
Reloads the page with a real page reload.
$respond->reboot()
toast_success
Sends a message indicating the operation was successful.
$respond->toast_success(string $text)
toast_warning
Sends a warning message.
$respond->toast_warning(string $text)
toast_info
Sends an informational message.
$respond->toast_info(string $text)
toast_error
Sends an error message.
$respond->toast_error(string $text)
put
Add an arbitrary command to be executed by the client.
$respond->put(string $command)
Create custom command
window.libs['custom_command'] = function (data) {
console.log(data); // dataValue1
};
And call it in the callback:
$respond->put('custom_command', ['dataValue1']);
Last modified: 09 May 2024