Fix the template API (#234)

This commit is contained in:
formsdev 2023-11-06 15:05:21 +05:30 committed by GitHub
parent cf0e923650
commit 8de1c94291
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -15,7 +15,7 @@ class TemplateController extends Controller
{ {
$limit = null; $limit = null;
if ($request->offsetExists('limit') && $request->get('limit') > 0) { if ($request->offsetExists('limit') && $request->get('limit') > 0) {
$limit = (int) $request->get('limit'); $limit = (int)$request->get('limit');
} }
$onlyMy = false; $onlyMy = false;
@ -24,12 +24,18 @@ class TemplateController extends Controller
} }
$templates = Template::limit($limit) $templates = Template::limit($limit)
->when(Auth::check() && !$onlyMy, function ($query) { ->when(Auth::check(), function ($query) use ($onlyMy) {
$query->where('publicly_listed', true); if ($onlyMy) {
$query->orWhere('creator_id', Auth::id()); $query->where('creator_id', Auth::id());
} else {
$query->where(function ($query) {
$query->where('publicly_listed', true)
->orWhere('creator_id', Auth::id());
});
}
}) })
->when(Auth::check() && $onlyMy, function ($query) { ->when(!Auth::check(), function ($query) {
$query->where('creator_id', Auth::id()); return $query->publiclyListed();
}) })
->orderByDesc('created_at') ->orderByDesc('created_at')
->get(); ->get();