Comments (14)
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.
yeah case changing generally seems like a bad idea. IMO it's good that it was removed
from ideas.
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.
@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.
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.
@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.
@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.
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.
@tomschlick, yep exactly. From requests do not go through middleware stack.
from ideas.
It doesn't matter if the actual FormRequest is going through the stack. The Request itself goes through the stack.
from ideas.
...
from ideas.
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.
I got the answer from Stack Overflow, thank you @taylorotwell
from ideas.
@wujunze Since you didn't provide the answer... was it $model->getAttribute('first_name')
?
from ideas.
Related Issues (20)
- [Proposal] Easy way to cancel notifications at time of sending
- Rendering Blade Components Outside of Views HOT 1
- Assert that a component has rendered on a page
- Service Container | Contextual Binding of the Methods
- [REQUEST] Enable flush method from dynamoDB cache HOT 3
- [Feature] Enable flush method from dynamoDB
- [Proposal] Support AOP with php8 Attribute
- laravel join select max of joined column
- Ability to get event name which fires in Eloquent booted method HOT 1
- Make `php artisan migrate:reset` work with *-schema.dump
- Size File Validation only deals with Kilobytes
- Suggesting that ".env.testing" file be added to .gitignore HOT 2
- add native support for dev containers HOT 3
- [9.x] Rename firstOrNew() to firstOrMake()
- Set property to a config value via an Attribute HOT 1
- Add support to get more information on the job class
- Allow pausing batches
- afterCommit on Queueable Anonymous Event Listeners
- Upsert for related models
- Command option to run scheduler in a particular timezone
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ideas.