Skip to content

Commit

Permalink
Fix the template API (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
formsdev authored Nov 6, 2023
1 parent cf0e923 commit 8de1c94
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/Http/Controllers/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function index(Request $request)
{
$limit = null;
if ($request->offsetExists('limit') && $request->get('limit') > 0) {
$limit = (int) $request->get('limit');
$limit = (int)$request->get('limit');
}

$onlyMy = false;
Expand All @@ -24,12 +24,18 @@ public function index(Request $request)
}

$templates = Template::limit($limit)
->when(Auth::check() && !$onlyMy, function ($query) {
$query->where('publicly_listed', true);
$query->orWhere('creator_id', Auth::id());
->when(Auth::check(), function ($query) use ($onlyMy) {
if ($onlyMy) {
$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) {
$query->where('creator_id', Auth::id());
->when(!Auth::check(), function ($query) {
return $query->publiclyListed();
})
->orderByDesc('created_at')
->get();
Expand Down

0 comments on commit 8de1c94

Please sign in to comment.