Is it possible to send POST data with `MenuItem::postAction()`?

I have a MenuItem in my Panel that I want to send a POST with:
MenuItem::make()
->label(
fn () => locale() === 'nl' ? 'English' : 'Nederlands'
)
->postAction(fn () => route('locale.update'))
->icon('heroicon-o-globe-alt'),
MenuItem::make()
->label(
fn () => locale() === 'nl' ? 'English' : 'Nederlands'
)
->postAction(fn () => route('locale.update'))
->icon('heroicon-o-globe-alt'),
However, I can't find any documentation on how to send POST data in the request. This route requires a locale field to be set. Is there a way to do this?
5 Replies
Bruno Pereira
Bruno Pereira3d ago
route('locale.update',['locale', $yourlocale])
grardb
grardbOP3d ago
That adds it to the query params, but this is a POST 😕
Bruno Pereira
Bruno Pereira3d ago
how do you have your route defined?
grardb
grardbOP3d ago
Route::post('locale', SetUserLocale::class)->name('locale.update');
Route::post('locale', SetUserLocale::class)->name('locale.update');
Bruno Pereira
Bruno Pereira3d ago
Route::post('locale/{locale}', SetUserLocale::class)->name('locale.update');
Route::post('locale/{locale}', SetUserLocale::class)->name('locale.update');
and then on the controller method have
(Request $request, $locale) {

}
(Request $request, $locale) {

}
and then
route('locale.update',['locale', $yourlocale])
route('locale.update',['locale', $yourlocale])
thats one way to handle it

Did you find this page helpful?