-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It does not work in api related routes #49
Comments
Hi Rafig, Thank you for reaching out with your issue regarding the use of toastr within an API route. I'd like to clarify a few important points that might help you. Firstly, the Regarding your current issue, both I'm curious about how you plan to display the toastr notifications triggered from API routes. Are you looking to send flash notification data back as part of a JSON response, or is there another mechanism you have in mind? Looking forward to your response. Best regards, |
Hello |
Hello Rafig, Thank you for providing more context on your use case. I understand the challenge of triggering flash notifications in an API environment due to the stateless nature of API routes. I have a solution that should work for your specific scenario: Since the toastr notifications rely on session data which is available only in web routes, you can redirect the user to an intermediate web route after handling the data from the bank gateway. Here’s a step-by-step explanation:
Here’s a simple example of how you can implement this: // In your API controller
public function handleBankCallback(Request $request) {
$result = // process the bank data
return redirect()->route('intermediate.route', ['result' => $result]);
}
// In your web.php
Route::get('/intermediate', function (Request $request) {
$result = $request->query('result');
flash($result === 'success' ? 'Transaction successful' : 'Transaction failed', $result);
return redirect()->route('final.view');
})->name('intermediate.route');
// In your final view
// Display the toastr notifications as you normally would This method ensures that your flash notifications are triggered within a context that supports session state, thereby maintaining the functionality you need without breaking the stateless nature of API routes. Let me know if this solution works for you or if you have any further questions! Best regards, |
When I use the toastr during a method that is executed by a route from within the api.php file; it does not work.
It works fine by all other root
The text was updated successfully, but these errors were encountered: