What do you think about this package by Dayle Rees? https://github.com/daylerees/sanitizer
Nov 4, 2015
5
Level 6
Best way to transform INPUT data
Hi.
I'm using dingo/api which uses Fractal to transform OUTPUT data, very nice.
How do you transform the input data? I know we could use Mutators/Accesors or override the "input" method of the FormRequest I think.
Imagine I want to save a user which but the username always in lowercase. Today I would do a "setUsernameAttribute" method on the User model but I would like to do somethig like this:
// method controller
public function register(UserRegisterRequest $request, UserInputTransformer $inputTransformer)
{
$data = $inputTransformer->transform($request->all());
User::create($data);
}
// input transformer
class UserInputTransformer {
public function transform($data)
{
return [
'username' => strtolower($data['username']),
// etc.
];
}
}
What do you think?
Please or to participate in this conversation.