XetaIO /
Xetaravel
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Xetaravel\Models\Presenters; |
||
| 6 | |||
| 7 | use Illuminate\Database\Eloquent\Casts\Attribute; |
||
| 8 | |||
| 9 | trait DiscussConversationPresenter |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * We must decrement the post count due to the first post being counted. |
||
| 13 | * |
||
| 14 | * @return Attribute |
||
| 15 | */ |
||
| 16 | protected function postCountFormated(): Attribute |
||
| 17 | { |
||
| 18 | return Attribute::make( |
||
| 19 | get: fn () => $this->post_count - 1 |
||
| 20 | ); |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Get the conversation url. |
||
| 25 | * |
||
| 26 | * @return Attribute |
||
| 27 | */ |
||
| 28 | protected function conversationUrl(): Attribute |
||
| 29 | { |
||
| 30 | return Attribute::make( |
||
| 31 | get: fn () => route('discuss.conversation.show', ['slug' => $this->slug, 'id' => $this->getKey()]) |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 32 | ); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Get the last page number for the conversation. |
||
| 37 | * |
||
| 38 | * @return Attribute |
||
| 39 | */ |
||
| 40 | protected function lastPage(): Attribute |
||
| 41 | { |
||
| 42 | return Attribute::make( |
||
| 43 | get: function () { |
||
| 44 | $posts = $this->post_count_formated; |
||
| 45 | |||
| 46 | if ($this->is_solved) { |
||
| 47 | $posts = $posts - 1; |
||
| 48 | } |
||
| 49 | |||
| 50 | $page = (int) ceil($posts / config('xetaravel.pagination.discuss.post_per_page')); |
||
| 51 | |||
| 52 | return $page ?: 1; |
||
| 53 | } |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | } |
||
| 57 |