Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f86906a

Browse files
committed
Input::exists function added.
New 'Input::exists' function for checking for the mere presence of input items.
1 parent c510e5f commit f86906a

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/Illuminate/Foundation/changes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
{"message": "Added 'assertViewMissing' method to TestCase.", "backport": null},
102102
{"message": "Added 'whereYear', 'whereMonth', and 'whereDay'.", "backport": null},
103103
{"message": "Added events for committing, rolling back, and starting transactions on databsae connections.", "backport": null},
104-
{"message": "Added 'Auth::id' method to just get the authenticate user ID from the session / recaller cookie.", "backport": null}
104+
{"message": "Added 'Auth::id' method to just get the authenticate user ID from the session / recaller cookie.", "backport": null},
105+
{"message": "New 'Input::exists' function for checking for the mere presence of input items.", "backport": null}
105106
],
106107
"4.0.*": [
107108
{"message": "Added implode method to query builder and Collection class.", "backport": null},

src/Illuminate/Http/Request.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,32 @@ public function secure()
157157
}
158158

159159
/**
160-
* Determine if the request contains a given input item.
160+
* Determine if the request contains a given input item key.
161+
*
162+
* @param string|array $key
163+
* @return bool
164+
*/
165+
public function exists($key)
166+
{
167+
$input = $this->all();
168+
169+
if (count(func_get_args()) > 1)
170+
{
171+
foreach (func_get_args() as $value)
172+
{
173+
if ( ! array_key_exists($value, $input)) return false;
174+
}
175+
176+
return true;
177+
}
178+
else
179+
{
180+
return array_key_exists($key, $input);
181+
}
182+
}
183+
184+
/**
185+
* Determine if the request contains a non-emtpy value for an input item.
161186
*
162187
* @param string|array $key
163188
* @return bool

0 commit comments

Comments
 (0)