Last active
May 12, 2017 15:47
-
-
Save kuroisuna/c1f216755ac0b97b80da647cd38d534f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
$rules = [ | |
'name' => 'required', | |
'age' => 'required|numeric|min:18', | |
'email' => 'email', | |
]; | |
// $data = $request->validated(); ['name' => 'Scott', 'age' => 66, 'email' => '[email protected]'] | |
// What if I need an aditional field that doesn't require validation? | |
// $data['status'] = $request->get('status'); ? | |
// What I currently do | |
$rules = [ | |
'name' => 'required', | |
'age' => 'required|numeric|min:18', | |
'email' => 'email', | |
]; | |
$allowedData = [ | |
'name', | |
'age', | |
'email', | |
'status', | |
]; | |
$request->only($allowedData); // ['name' => 'Scott', 'age' => 66, 'email' => '[email protected]', 'status' => 'av']; | |
// Utopia | |
$rules = [ | |
'name' => 'required', | |
'age' => 'required|numeric|min:18', | |
'email' => 'email', | |
'status' => ':string:', // Cast, Modifiers, Sanitizers, Zend like? | |
]; | |
// $data = $request->validated(); ['name' => 'Scott', 'age' => 66, 'email' => '[email protected]', 'status' => 'av']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment