Skip to content

Commit 485b2de

Browse files
authored
Merge pull request #628 from filamentphp/feat/draft-plugins
feat: add draft status for plugins
2 parents f1b265d + e840691 commit 485b2de

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

app/Actions/GetPluginsListData.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ function () use ($plugins): array {
2828
->get()
2929
->pluck('count', 'starrable_id');
3030

31-
return Plugin::query()
31+
return Plugin::with(['author'])
32+
->draft(false)
3233
->when(
3334
$plugins,
3435
fn (EloquentBuilder $query) => $query->whereKey($plugins),
3536
)
3637
->orderByDesc('publish_date')
37-
->with(['author'])
3838
->get()
3939
->map(fn (Plugin $plugin): array => [
4040
...$plugin->getDataArray(),

app/Http/Controllers/Api/PluginController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44

55
use App\Http\Controllers\Controller;
66
use App\Models\Plugin;
7+
use Illuminate\Database\Eloquent\Builder;
8+
use Illuminate\Http\Request;
79

810
class PluginController extends Controller
911
{
10-
public function index()
12+
public function index(Request $request)
1113
{
12-
return Plugin::paginate();
14+
return Plugin::query()
15+
->when(
16+
$request->boolean('draft'),
17+
fn (Builder $query, bool $condition) => $query->draft($condition)
18+
)
19+
->paginate();
1320
}
1421

1522
public function show(Plugin $plugin)

app/Models/Plugin.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Plugin extends Model implements Starrable
2727
'has_translations' => 'boolean',
2828
'is_lemon_squeezy_embedded' => 'boolean',
2929
'is_presale' => 'boolean',
30+
'is_draft' => 'boolean',
3031
'versions' => 'array',
3132
'publish_date' => 'date',
3233
'docs_urls' => 'array',
@@ -46,6 +47,7 @@ public static function schema(Blueprint $table)
4647
$table->boolean('has_dark_theme')->default(false);
4748
$table->boolean('has_translations')->default(false);
4849
$table->string('image')->nullable();
50+
$table->boolean('is_draft')->nullable()->default(false);
4951
$table->boolean('is_lemon_squeezy_embedded')->nullable()->default(false);
5052
$table->boolean('is_presale')->nullable()->default(false);
5153
$table->string('name');
@@ -67,6 +69,15 @@ public function stars(): MorphMany
6769
return $this->morphMany(Star::class, 'starrable');
6870
}
6971

72+
public function scopeDraft(Builder $query, bool $condition = true): Builder
73+
{
74+
if (! $condition) {
75+
return $query->whereNull('is_draft')->orWhere('is_draft', false);
76+
}
77+
78+
return $query->where('is_draft', true);
79+
}
80+
7081
public function getDocUrl(string $version = null): ?string
7182
{
7283
if (filled($this->docs_url)) {
@@ -106,6 +117,11 @@ public function isFree(): bool
106117
return blank($this->price) && blank($this->anystack_id);
107118
}
108119

120+
public function isDraft(): bool
121+
{
122+
return (bool) $this->is_draft;
123+
}
124+
109125
public function getCheckoutUrl(): ?string
110126
{
111127
if (filled($this->checkout_url)) {

resources/views/plugins/view-plugin.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ class="absolute inset-0 -z-10 h-full w-full -translate-x-1.5 translate-y-1.5 rou
545545
</div>
546546
</div>
547547

548-
@if (count($otherPlugins = $plugin->author->plugins()->where('slug', '!=', $plugin->slug)->inRandomOrder()->limit(3)->get()))
548+
@if (count($otherPlugins = $plugin->author->plugins()->draft(false)->where('slug', '!=', $plugin->slug)->inRandomOrder()->limit(3)->get()))
549549
{{-- More From This Author --}}
550550
<div>
551551
<div class="text-lg font-extrabold">

0 commit comments

Comments
 (0)