本文整理匯總了PHP中app\Member::withTrashed方法的典型用法代碼示例。如果您正苦於以下問題:PHP Member::withTrashed方法的具體用法?PHP Member::withTrashed怎麽用?PHP Member::withTrashed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Member
的用法示例。
在下文中一共展示了Member::withTrashed方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: numMembers
private function numMembers()
{
$numActive = Member::all()->where('is_active', 1)->count();
$numInactive = Member::all()->where('is_active', 0)->count();
$numDischarged = Member::onlyTrashed()->count();
$numTotal = Member::withTrashed()->count();
return ['numActive' => $numActive, 'numInactive' => $numInactive, 'numDischarged' => $numDischarged, 'numTotal' => $numTotal];
}
示例2: search
/**
* Search the resource by providing a querystring
*
* @return Response
*/
public function search(Request $request)
{
// ?discharged -- [ none | include | only ]
$withDischarged = $request->query('discharged', 'none');
if ($withDischarged == 'include') {
$query = Member::withTrashed();
} elseif ($withDischarged == 'only') {
$query = Member::onlyTrashed();
} else {
$query = Member::select();
}
// join on 3p table
$query->leftJoin('posting_promo', function ($join) {
$join->on('members.regt_num', '=', 'posting_promo.regt_num');
});
$query->select('members.*', 'posting_promo.new_rank as rank');
if ($request->has('keywords')) {
$keywords = explode(' ', $request->query('keywords'));
foreach ($keywords as $keyword) {
// If keyword resembles a regt number_format
if ($this->keywordLikeRegtNum($keyword)) {
$query->where('members.regt_num', 'like', "{$keyword}%");
continue;
}
// If keyword matches a known rank abbrev
if ($this->keywordLikeRank($keyword)) {
$rank = $this->keywordExtractRank($keyword);
$query->where('rank', $rank);
continue;
}
// Otherwise add this as a name search
$query->where(function ($query) use($keyword) {
$query->where('last_name', 'like', "%{$keyword}%")->orWhere('first_name', 'like', "%{$keyword}%");
});
}
} else {
foreach ($request->only('rank', 'last_name', 'first_name', 'regt_num') as $name => $input) {
$input = trim($input);
if (!empty($input)) {
$query->where($name, 'like', "{$input}%");
$query->orderBy($name, 'asc');
}
}
foreach ($request->only('sex') as $name => $input) {
// ('sex', 'is_active')
$input = trim($input);
if (!empty($input)) {
$query->where($name, $input);
}
}
}
// return var_dump($input);
return response()->json(['members' => $query->get()]);
}