Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

waffleophagus's avatar

Is it possible to make Livewire Update a GET and not a POST?

I am attempting to use litefs (https://fly.io/docs/litefs/) to allow for replication of sqlite databases since sqlite has insane read speeds. Here's the problem: LiteFS looks at the request type to determine if it contains a write, and from what I see, all my livewire requests, regardless of if they make a write go as a post, which LiteFS interprets as a write, and makes a request to the primary (which often times in my app is on the other side of the world!) Is there a way to make specific livewire requests gets instead of posts if I'm confident they aren't updating the database? (For example, a moving of a pagenation of a table?)

0 likes
1 reply
LaryAI's avatar
Level 58

In Livewire, all component updates are typically sent as POST requests because they are designed to handle state changes, which often involve data mutations. However, if you have specific actions that do not modify the state and you want to use GET requests to avoid unnecessary write operations, you can consider the following approach:

  1. Use Alpine.js for Non-Mutating Actions: For actions that do not require state changes, you can use Alpine.js or plain JavaScript to handle them. This way, you can make GET requests directly without involving Livewire.

  2. Custom Livewire Method for GET Requests: If you still want to use Livewire for some actions but need them to be GET requests, you can create a custom method in your Livewire component that you call via a regular GET request. This method can return a view or data without changing the state.

Here's an example of how you might implement this:

  1. Create a Route for the GET Request:
// In your web.php or routes file
Route::get('/your-component-action', [YourComponent::class, 'yourMethod'])->name('your.component.action');
  1. Define the Method in Your Livewire Component:
use Livewire\Component;

class YourComponent extends Component
{
    public function yourMethod()
    {
        // Perform actions that do not mutate state
        // Return a view or JSON response
        return response()->json(['data' => 'Your data here']);
    }
}
  1. Call the GET Request Using JavaScript:
<script>
    function fetchData() {
        fetch('/your-component-action')
            .then(response => response.json())
            .then(data => {
                console.log(data);
                // Handle the data as needed
            });
    }
</script>

<button onclick="fetchData()">Fetch Data</button>

By using this approach, you can bypass Livewire's default POST request behavior for specific actions that do not require state changes, thus avoiding unnecessary write operations in LiteFS.

Please or to participate in this conversation.