fix searching textures in skin library

This commit is contained in:
Pig Fang 2020-04-27 18:46:22 +08:00
parent 5ea1187f2a
commit 55990f24be
2 changed files with 11 additions and 3 deletions

View File

@ -59,9 +59,12 @@ class SkinlibController extends Controller
})
->when($user, function (Builder $query, User $user) {
if (!$user->isAdmin()) {
return $query
->where('public', true)
->orWhere('uploader', $user->uid);
// use closure-style `where` clause to lift up SQL priority
return $query->where(function (Builder $query) use ($user) {
$query
->where('public', true)
->orWhere('uploader', $user->uid);
});
}
}, function (Builder $query) {
// show public textures only to anonymous visitors

View File

@ -55,6 +55,11 @@ class SkinlibControllerTest extends TestCase
['tid' => $steve->tid, 'nickname' => $steve->owner->nickname],
],
]);
$user = factory(User::class)->create();
$list = $this->actingAs($user)
->getJson('/skinlib/list?keyword=a')
->decodeResponseJson('data');
$this->assertCount(1, $list);
// with uploader
$this->getJson('/skinlib/list?uploader='.$steve->uploader)