本文整理匯總了PHP中Illuminate\Database\Eloquent\Collection::reject方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::reject方法的具體用法?PHP Collection::reject怎麽用?PHP Collection::reject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Database\Eloquent\Collection
的用法示例。
在下文中一共展示了Collection::reject方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: filterOnMethods
/** After the Eloquent has run on the attributes and returned an eloquent collection,
* this method takes the collection and $querySets as above,
* [$key=>['val'=>$val,'crit'=>$crit,'parm0'=>$parm0.....
* @param Eloquent Collection $collection
* @param array $querySets or null to take from local object
*/
public function filterOnMethods(Collection $collection, $matchObjs=null) {
//pkdebug("Yes, trying to filter.");
if (!$matchObjs || !is_arrayish($matchObjs)) $matchObjs = $this->getMatchObjs();
if (!$matchObjs || !is_arrayish($matchObjs)) return $collection;
$numpre = count($matchObjs);
$modelName = $collection-> getQueueableClass();
//pkdebug("The num of match objs before: The QC is: [ $modelName ], the num $numpre -- is mine here?");
//foreach ($matchObjs as $ma) { if ($ma->compfield == 'assetdebtratio') pkdebug("After buildQS, The MA is: ", $ma); }
$trimmedMatches = PkMatch::filterMatchArr($matchObjs,
['modelName'=>$modelName,'modelMethods'=>true,'emptyCrit'=>true]);
//pkdebug("The Trimmed Match Collection:", $trimmedMatches);
if (!count($trimmedMatches)) return $collection;
$trimmedCollection = $collection->reject(function ($item) use ($trimmedMatches) {
foreach($trimmedMatches as $match) {
$methodName = $match->method;
$methodResult = $item->$methodName();
$passed = $match->satisfy($methodResult);
$reject = !$passed;
if ($reject) return $reject;
} ## Passed all the criteria; don't reject
return false;
});
return $trimmedCollection;
}
示例2: tweetable
/**
* Retrieve only those conferences which should be tweeted.
*
* @param \Illuminate\Database\Eloquent\Collection $conferences
*
* @return \Illuminate\Database\Eloquent\Collection
*/
private function tweetable($conferences)
{
return $conferences->reject(function ($conference) {
$starts = $conference->cfp_starts_at;
$ends = $conference->cfp_ends_at;
return $starts->isSameDay($ends);
});
}