Skip to content

Instantly share code, notes, and snippets.

@kuroisuna
Last active May 12, 2017 15:47
Show Gist options
  • Save kuroisuna/c1f216755ac0b97b80da647cd38d534f to your computer and use it in GitHub Desktop.
Save kuroisuna/c1f216755ac0b97b80da647cd38d534f to your computer and use it in GitHub Desktop.
<?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