Skip to content

Commit

Permalink
Merge pull request #628 from filamentphp/feat/draft-plugins
Browse files Browse the repository at this point in the history
feat: add draft status for plugins
  • Loading branch information
danharrin authored Jan 9, 2025
2 parents f1b265d + e840691 commit 485b2de
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/Actions/GetPluginsListData.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ function () use ($plugins): array {
->get()
->pluck('count', 'starrable_id');

return Plugin::query()
return Plugin::with(['author'])
->draft(false)
->when(
$plugins,
fn (EloquentBuilder $query) => $query->whereKey($plugins),
)
->orderByDesc('publish_date')
->with(['author'])
->get()
->map(fn (Plugin $plugin): array => [
...$plugin->getDataArray(),
Expand Down
11 changes: 9 additions & 2 deletions app/Http/Controllers/Api/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

use App\Http\Controllers\Controller;
use App\Models\Plugin;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;

class PluginController extends Controller
{
public function index()
public function index(Request $request)
{
return Plugin::paginate();
return Plugin::query()
->when(
$request->boolean('draft'),
fn (Builder $query, bool $condition) => $query->draft($condition)
)
->paginate();
}

public function show(Plugin $plugin)
Expand Down
16 changes: 16 additions & 0 deletions app/Models/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Plugin extends Model implements Starrable
'has_translations' => 'boolean',
'is_lemon_squeezy_embedded' => 'boolean',
'is_presale' => 'boolean',
'is_draft' => 'boolean',
'versions' => 'array',
'publish_date' => 'date',
'docs_urls' => 'array',
Expand All @@ -46,6 +47,7 @@ public static function schema(Blueprint $table)
$table->boolean('has_dark_theme')->default(false);
$table->boolean('has_translations')->default(false);
$table->string('image')->nullable();
$table->boolean('is_draft')->nullable()->default(false);
$table->boolean('is_lemon_squeezy_embedded')->nullable()->default(false);
$table->boolean('is_presale')->nullable()->default(false);
$table->string('name');
Expand All @@ -67,6 +69,15 @@ public function stars(): MorphMany
return $this->morphMany(Star::class, 'starrable');
}

public function scopeDraft(Builder $query, bool $condition = true): Builder
{
if (! $condition) {
return $query->whereNull('is_draft')->orWhere('is_draft', false);
}

return $query->where('is_draft', true);
}

public function getDocUrl(string $version = null): ?string
{
if (filled($this->docs_url)) {
Expand Down Expand Up @@ -106,6 +117,11 @@ public function isFree(): bool
return blank($this->price) && blank($this->anystack_id);
}

public function isDraft(): bool
{
return (bool) $this->is_draft;
}

public function getCheckoutUrl(): ?string
{
if (filled($this->checkout_url)) {
Expand Down
2 changes: 1 addition & 1 deletion resources/views/plugins/view-plugin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ class="absolute inset-0 -z-10 h-full w-full -translate-x-1.5 translate-y-1.5 rou
</div>
</div>

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

0 comments on commit 485b2de

Please sign in to comment.