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

6 messages · Page 1 of 1 (latest)

reef pier
#

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'),

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?

icy vine
#

route('locale.update',['locale', $yourlocale])

reef pier
#

That adds it to the query params, but this is a POST 😕

icy vine
#

how do you have your route defined?

reef pier
#
Route::post('locale', SetUserLocale::class)->name('locale.update');
icy vine
#
Route::post('locale/{locale}', SetUserLocale::class)->name('locale.update');

and then on the controller method have

(Request $request, $locale) {

}

and then

route('locale.update',['locale', $yourlocale])