Skip to content

Commit

Permalink
修复翻页后搜索条件丢失的 bug Closed #343
Browse files Browse the repository at this point in the history
  • Loading branch information
wisp-x committed Mar 22, 2022
1 parent 769eb4b commit 683a0a4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/Admin/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ private function share()

public function index(Request $request): View
{
$groups = Group::query()->when($request->query('keywords'), function (Builder $builder, $keywords) {
$keywords = $request->query('keywords');
$groups = Group::query()->when($keywords, function (Builder $builder, $keywords) {
$builder->where('name', 'like', "%{$keywords}%");
})->withCount('users')->withCount('strategies')->latest()->paginate();

$groups->appends(compact('keywords'));

$this->share();

return view('admin.group.index', compact('groups'));
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/Admin/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class ImageController extends Controller
{
public function index(Request $request): View
{
$keywords = $request->query('keywords');
$images = Image::query()->with(['user' => function (BelongsTo $belongsTo) {
$belongsTo->withSum('images', 'size');
}, 'album', 'group', 'strategy'])->when($request->input('keywords'), function (Builder $builder, $keywords) {
}, 'album', 'group', 'strategy'])->when($keywords, function (Builder $builder, $keywords) {
$words = [];
$qualifiers = [
'name:', 'album:', 'group:', 'strategy:', 'email:', 'extension:', 'md5:', 'sha1:', 'ip:', 'is:', 'order:',
Expand Down Expand Up @@ -65,13 +66,14 @@ public function index(Request $request): View
foreach ($words as $word) {
$builder->where('origin_name', 'like', "%{$word}%")->orWhere('alias_name', 'like', "%{$word}%");
}
})->latest()->paginate(40);
})->latest()->paginate(1);
$images->getCollection()->each(function (Image $image) {
$image->append('url', 'pathname', 'thumb_url');
$image->album?->setVisible(['name']);
$image->group?->setVisible(['name']);
$image->strategy?->setVisible(['name']);
});
$images->appends(compact('keywords'));

return view('admin.image.index', compact('images'));
}
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/Admin/StrategyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ class StrategyController extends Controller
{
public function index(Request $request): View
{
$strategies = Strategy::query()->when($request->query('keywords'), function (Builder $builder, $keywords) {
$keywords = $request->query('keywords');
$strategies = Strategy::query()->when($keywords, function (Builder $builder, $keywords) {
$builder->where('name', 'like', "%{$keywords}%")->orWhere('intro', 'like', "%{$keywords}%");
})->withCount('images')->withSum('images', 'size')->latest()->paginate();

$strategies->appends(compact('keywords'));

return view('admin.strategy.index', compact('strategies'));
}

Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ class UserController extends Controller
public function index(Request $request): View
{
$status = $request->query('status');
$keywords = $request->query('keywords');
$users = User::query()->when($status > -1, function (Builder $builder) use ($status) {
$builder->where('status', $status);
})->when($request->query('keywords'), function (Builder $builder, $keywords) {
})->when($keywords, function (Builder $builder, $keywords) {
$builder->where('name', 'like', "%{$keywords}%")->orWhere('email', 'like', "%{$keywords}%");
})->with('group')->withSum('images', 'size')->latest()->paginate();
$users->getCollection()->each(function (User $user) {
$user->group->setVisible(['name']);
});
$statuses = [-1 => '全部', 1 => '正常', 0 => '冻结'];

$users->appends(compact('status', 'keywords'));

return view('admin.user.index', compact('users', 'statuses'));
}

Expand Down

0 comments on commit 683a0a4

Please sign in to comment.