Skip to content
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
6 changes: 5 additions & 1 deletion app/Http/Requests/CommentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class CommentRequest extends FormRequest
* Determine if the user is authorized to make this request.
*
*/
public const MAX_CONTENT_LENGTH = 500;

public function authorize(): bool
{
return true;
Expand All @@ -22,10 +24,12 @@ public function authorize(): bool
*/
public function rules(): array
{
$maxLength = self::MAX_CONTENT_LENGTH;

return [
'commentable_type' => 'required|string',
'commentable_id' => 'required|min:1',
'content' => 'required|string|min:1|max:500',
'content' => "required|string|min:1|max:{$maxLength}",
'parent_id' => 'sometimes|exists:comments,id',
];
}
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'none_comments' => 'There are no comments yet.',
'authentication_required' => 'Authentication required',
'must_log_in' => 'You must log in to post a comment.',
'enter_your_message' => 'Enter your message here (markdown supported)',
'enter_your_message' => 'Message input field, maximum :max characters (Markdown supported)',
'submit' => 'Submit',
'edit_comment' => 'Edit Comment',
'update_comment_here' => 'Update your message here:',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ru/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'none_comments' => 'Комментарии отсутствуют.',
'authentication_required' => 'Необходима авторизация',
'must_log_in' => 'Вы должны авторизоваться для создания комментария.',
'enter_your_message' => 'Поле ввода сообщения (поддерживается markdown)',
'enter_your_message' => 'Поле ввода сообщения, максимум :max символов (поддерживается markdown)',
'submit' => 'Отправить',
'edit_comment' => 'Редактировать',
'update_comment_here' => 'Изменить сообщение здесь:',
Expand Down
10 changes: 7 additions & 3 deletions resources/views/components/comment/_comment.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ class="btn btn-sm btn-link text-uppercase p-0 mr-2">
{{ html()->hidden('commentable_type') }}
{{ html()->hidden('commentable_id') }}
<div class="form-floating">
{{ html()->textarea('content')->class('form-control x-min-h-300px')->required() }}
<label for="content" class="w-100 text-wrap">{{ __('comment.enter_your_message') }}</label>
{{ html()
->textarea('content')
->class('form-control x-min-h-300px')
->attribute('maxlength', $maxCommentLength)
->required() }}
<label for="content" class="w-100 text-wrap">{{ __('comment.enter_your_message', ['max' => $maxCommentLength]) }}</label>
</div>
</div>
<div class="modal-footer text-left">
Expand All @@ -79,7 +83,7 @@ class="btn btn-sm btn-link text-uppercase p-0 mr-2">
</div>
@endcan
@can('reply', $comment)
@include('components.comment.reply._modal')
@include('components.comment.reply._modal', ['maxCommentLength' => $maxCommentLength])
@endcan
</div>
</div>
9 changes: 7 additions & 2 deletions resources/views/components/comment/_form.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@php
/**
* @var \Illuminate\Database\Eloquent\Model $model
* @var int $maxLength
*/
@endphp
<div class="card">
Expand All @@ -9,8 +10,12 @@
{{ html()->hidden('commentable_type')->value(get_class($model)) }}
{{ html()->hidden('commentable_id')->value($model->id) }}
<div class="form-floating">
{{ html()->textarea('content')->class('form-control x-min-h-100px')->required() }}
<label for="content" class="w-100 text-wrap">{{ __('comment.enter_your_message') }}</label>
{{ html()
->textarea('content')
->class('form-control x-min-h-100px')
->attribute('maxlength', $maxCommentLength)
->required() }}
<label for="content" class="w-100 text-wrap">{{ __('comment.enter_your_message', ['max' => $maxCommentLength]) }}</label>
</div>
<div class="mt-3">
{{ html()->submit(__('comment.submit'))->class('btn btn-success btn-sm text-uppercase') }}
Expand Down
8 changes: 6 additions & 2 deletions resources/views/components/comment/reply/_modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
{{ html()->hidden('commentable_id')->value($comment->commentable_id) }}
{{ html()->hidden('parent_id')->value($comment->id) }}
<div class="form-floating">
{{ html()->textarea('content')->class('form-control x-min-h-300px')->required() }}
<label for="content" class="w-100 text-wrap">{{ __('comment.enter_your_message') }}</label>
{{ html()
->textarea('content')
->class('form-control x-min-h-300px')
->attribute('maxlength', $maxCommentLength)
->required() }}
<label for="content" class="w-100 text-wrap">{{ __('comment.enter_your_message', ['max' => $maxCommentLength]) }}</label>
</div>
</div>
<div class="modal-footer text-left">
Expand Down
6 changes: 4 additions & 2 deletions resources/views/components/comments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* @var \Illuminate\Database\Eloquent\Model $model
* @var \App\Models\Comment $comment
*/
use App\Http\Requests\CommentRequest;
$maxCommentLength = CommentRequest::MAX_CONTENT_LENGTH;
@endphp
<div class="mt-2">
@if ($model->comments->isEmpty())
Expand All @@ -12,11 +14,11 @@
@endif
<ul class="list-unstyled">
@foreach ($model->comments as $comment)
@include('components.comment._comment', ['comment' => $comment])
@include('components.comment._comment', ['comment' => $comment, 'maxCommentLength' => $maxCommentLength])
@endforeach
</ul>
@auth
@include('components.comment._form')
@include('components.comment._form', ['maxCommentLength' => $maxCommentLength])
@else
<div class="card">
<div class="card-body">
Expand Down