How do you have Livewire use the current session of the authenticated user?

  • posting a form or Ajax post from within a livewire component results in 419 error from Laravel. I believe this is because request does not share the same session as the main page. Is there a way to get this to work? I need to submit an AJAX post request from within a livewire component, as the form fields are dynamic and not linkable via wire:model.

This ended up being caused by browserSync (Laravel Mix) running off of a different domain and causing CORS issues. Any suggestions on how to prevent that, or can we just no use browser sync for these situations?

I can’t speak on CORS, but am wondering what you mean by dynamic form fields. Do you have a list of items of the same type that can be added to or subtracted from? If that is the case, check out this post which should give some insight on how to handle an array of items in Livewire - Is there a way to handle inputs with the same name?.

By “dynamic”, I mean that the developer can insert any form fields they want. The form fields are not tied to the livewire component, so I cannot use wire:model on them, but instead have to make an AJAX request to post the information.

Got ya. I am trying to think if that could be possible with Livewire :thinking:

In regards to CORS, are you on Laravel 7? It has first-party CORS support by configuring the cors config - https://laravel.com/docs/7.x/routing#cors. Not sure if that helps.

This is more of a browserSync configuration issue, I think. For now I’m just not using it. Thanks for the reference to the CORS settings in Laravel 7, I have looked at them, but will give them another read-through :).