jeudi 6 octobre 2016

Alternative to Laravel collection's only() and intersect() methods

$request
{ "input1":"50" , "input2":"0" , "input3":"60000" }

$validkeys
{ "input1" , "input2" , "input3", "input4", "input5" }

$request->only($validkeys)
[ extra keys can change earlier values to null]
{ "input1":"50" , "input2":"0" , "input3":"60000" , "input4":null , "input5":null }

$request->intersect($validkeys) [ removes key with value as 0]
{ "input1":"50" , "input3":"60000" }

All I want is $request with validation.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire