Skip to content

Commit

Permalink
feat: added custom HasDrafts trait that is_published fillable property
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Frey <mail@lukasfrey.cz>
  • Loading branch information
lukas-frey committed Apr 17, 2023
1 parent 5372151 commit 2ecb13a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Admin/Resources/Concerns/Draftable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Guava\FilamentDrafts\Admin\Resources\Concerns;

use Exception;
use Guava\FilamentDrafts\Concerns\HasDrafts;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
use Oddvalue\LaravelDrafts\Concerns\HasDrafts;

/**
* Draftable trait for Filament resources.
Expand All @@ -22,7 +22,7 @@ trait Draftable
*/
public static function getEloquentQuery(): Builder
{
if (! Arr::has(class_uses(static::$model), HasDrafts::class)) {
if (! Arr::hasAny(class_uses(static::$model), [HasDrafts::class, \Oddvalue\LaravelDrafts\Concerns\HasDrafts::class])) {
throw new Exception('The resource\'s associated model must implement the HasDrafts trait.');
}

Expand Down
14 changes: 14 additions & 0 deletions src/Concerns/HasDrafts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Guava\FilamentDrafts\Concerns;

trait HasDrafts
{
use \Oddvalue\LaravelDrafts\Concerns\HasDrafts;

public function initializeHasDrafts(): void
{
$this->fillable[] = 'is_published';
}

}

0 comments on commit 2ecb13a

Please # to comment.