Skip to content

Add edited to post #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ A forum package for Filament apps that provides both admin and frontend resource
}
```

4. Add `HasFavoriteForumPost` trait to your User model:

```php
use Tapp\FilamentForum\Models\Traits\HasFavoriteForumPost;

class User extends Authenticatable
{
// ...
use HasFavoriteForumPost;
// ...
}
```

That's it! The plugins will auto-register with Filament and be ready to use.

## Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
class="w-10 h-10 rounded-full"
>
<div>
<h3 class="text-lg font-semibold text-gray-900">{{ $record->name }}</h3>
<h3 class="text-lg font-semibold text-gray-900">
{{ $record->name }}
@if($record->hasBeenEdited())
<span class="text-sm text-gray-500 font-normal pl-2">edited</span>
@endif
</h3>
<p class="text-sm text-gray-500">
@if($record->getLastCommentTime())
Last reply {{ $record->getLastCommentTime() }}
Expand Down Expand Up @@ -88,4 +93,4 @@ class="w-8 h-8 rounded-full border-2 border-white"
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Kirschbaum\Commentions\Filament\Infolists\Components\CommentsEntry;
use Illuminate\Database\Eloquent\Model;
use App\Models\User;
use Tapp\FilamentForum\Models\ForumPost;

class ForumPostInfolist
{
Expand Down Expand Up @@ -36,6 +37,10 @@ public static function configure(Schema $schema): Schema
TextEntry::make('created_at')
->hiddenLabel()
->since(),
TextEntry::make('updated_at')
->label('Last edited')
->since()
->visible(fn (ForumPost $record) => $record->hasBeenEdited()),
])
->columnSpan(1),
]),
Expand All @@ -47,4 +52,4 @@ public static function configure(Schema $schema): Schema
]),
]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make(fn (ForumPost $record) => $record->user->name.' - '.$record->created_at->diffForHumans())
Section::make(fn (ForumPost $record) => $record->user->name.' - '.$record->created_at->diffForHumans() . ($record->hasBeenEdited() ? ' (edited)' : ''))
->headerActions([
Action::make('favorite')
->iconButton()
Expand Down Expand Up @@ -70,4 +70,4 @@ public static function configure(Schema $schema): Schema
])
]);
}
}
}
7 changes: 6 additions & 1 deletion src/Models/ForumPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,9 @@ public function getCommentAuthors(): Collection
/** @phpstan-ignore-next-line */
->map(fn ($comment) => $comment->author);
}
}

public function hasBeenEdited(): bool
{
return $this->created_at->ne($this->updated_at);
}
}