GithubHelp home page GithubHelp logo

Comments (4)

itsgoingd avatar itsgoingd commented on September 18, 2024

Hey, I can't see any weird behavior with a new Laravel + Jetstream installation. Can you share a simple repo demonstrating this issue?

from clockwork.

zaminhub avatar zaminhub commented on September 18, 2024

Sorry for late response. Here is demo repo https://github.com/zaminhub/jetstream.test.git
cloclwork installed store method doesn't work.

from clockwork.

zaminhub avatar zaminhub commented on September 18, 2024

Hello @itsgoingd Did you check the demo repo above?

from clockwork.

itsgoingd avatar itsgoingd commented on September 18, 2024

Hey, sorry, forgot about this one, thanks for reminding me. Turns out this is quite a convoluted issue. I will try to explain.

The code that triggers this behavior is this line in your javascript code:

https://github.com/zaminhub/jetstream.test/blob/master/resources/js/Pages/Posts/PostModal.vue#L19

This ends up sending a POST request with an empty _method override when trying to create new posts. When editing existing posts, the override is set to PUT, making it work.

On server-side, Clockwork checks the method of the incoming request, very early in the processing. To do so, we call $request->getMethod(), which is a method from the underlying Symfony HTTP request implementation. This method does a bunch of things, resolves the base request method, tries to apply various types of overrides and validates the result.

Since your app is sending request with an empty _method override, the method executes all the way up to the following validation step, which fails (since $method is an empty string) and an exception is thrown. I assume since this is very early in the request processing, the exception ends up being interpreted as 404 error (haven't looked into this part that much).

https://github.com/symfony/http-foundation/blob/7.1/Request.php#L1166-L1168

Well, a good question is, why does this work without Clockwork?

Turns out, Laravel includes a middleware, that replaces empty strings in the request by nulls. Now when we call the same getMethod() method, we will hit this early return and never reach the exception part.

https://github.com/symfony/http-foundation/blob/7.1/Request.php#L1156-L1158

The issue with Clockwork installed is the execution order, which looks like this:

Request is received
Clockwork calls getMethod() // _method is empty string and exception is thrown
ConvertEmptyStringsToNull middleware is ran
Routing calls getMethod() // _method is null now, so the call defaults to POST

TL;DR I'm not sure if or how we want to fix this in Clockwork, but you can trivially fix this on your side, by adding POST as default value to _method, or not including that key at all.

from clockwork.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.