Giter VIP home page Giter VIP logo

Comments (14)

robclancy avatar robclancy commented on September 28, 2024

This caused issue after issue when it was done. Many versions of this were written and finally support was removed because there was always some way it bugged out or confused developers.

from ideas.

tomschlick avatar tomschlick commented on September 28, 2024

yeah case changing generally seems like a bad idea. IMO it's good that it was removed

from ideas.

andrewmclagan avatar andrewmclagan commented on September 28, 2024

Although there is the persistent issue:

When using Laravel as a RESTful API serving a javascript (or other) front end such as react or angular. The preference for such languages is camel case. This causes problems with linters and other platform specifics.

Is there no possible way?

from ideas.

tomschlick avatar tomschlick commented on September 28, 2024

@andrewmclagan you could always use something like dingo/api or fractal to format your api responses the way you need them. but by default doing transforms on attribute/variable names seems kind of dangerous in terms of bugs

from ideas.

andrewmclagan avatar andrewmclagan commented on September 28, 2024

Im doing exactly that and it works fine.

Although we also implemented a middleware to transform incoming requests from camleCase to snake_case. Basically the reverse of the above. So we would get snake_case in and camelCase out without messing up Laravels picky internals.

The problem with that approach is we also validate with FormRequests and they do not go through any HTTP middlewares within the app (for reasons i do not understand), thus skipping our transformer and failing validation e.g.

Cannot find 'first_name' field in the request

Well .. no you cant. Laravel has not run my middleware so its still firstName

from ideas.

lagbox avatar lagbox commented on September 28, 2024

@andrewmclagan
Im not sure why you keep thinking the middleware stack gets 'skipped'.
Create a FormRequest and add a dd('in form request') somewhere, anywhere. Now add a test middleware to the route you are going to use that FormRequest in. In this middleware's handle method do a dd('in middleware').
What result do you think you will see?

from ideas.

tomschlick avatar tomschlick commented on September 28, 2024

@lagbox from what i'm seeing, form requests are initialized before the data is sent through middleware.

so even if you modify the request in the middleware when the form request validate() method is used it has the original request info, not the modified data.

from ideas.

lagbox avatar lagbox commented on September 28, 2024

Yea that is the issue, that is not the behavior I see currently :-).

If I merge inputs in a middleware, my FormRequest mirrors this ( dd($this->all()) in validate() ). Also in the controller doing dd($formrequest->all()) also mirrors this.

So it would not be possible for the request to not have passed through the middleware, or I would not have these merged inputs available, or the session store on the request, or the user resolver correctly bound to the request, or the csrf middleware checking the token, etc ...

I am on 5.2.29 btw.

from ideas.

andrewmclagan avatar andrewmclagan commented on September 28, 2024

@tomschlick, yep exactly. From requests do not go through middleware stack.

from ideas.

lagbox avatar lagbox commented on September 28, 2024

It doesn't matter if the actual FormRequest is going through the stack. The Request itself goes through the stack.

from ideas.

andrewmclagan avatar andrewmclagan commented on September 28, 2024

...

from ideas.

wujunze avatar wujunze commented on September 28, 2024

Hello
The Laravel version I use is 5.5

It is strange. I have a first_name column in my DB, so I need to use $user->first_name. According to what you said, we can use $user->firstName. But it does not work. Have I forgotten something?

Thanks in advance.
@taylorotwell

from ideas.

wujunze avatar wujunze commented on September 28, 2024

I got the answer from Stack Overflow, thank you @taylorotwell

from ideas.

sisve avatar sisve commented on September 28, 2024

@wujunze Since you didn't provide the answer... was it $model->getAttribute('first_name')?

from ideas.

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.