本文整理汇总了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()]);
}