Skip to content

Commit

Permalink
Fix permission issue and make category nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
sangnguyenplus committed Jan 31, 2025
1 parent 0184dc5 commit e1bd23e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 10 deletions.
21 changes: 21 additions & 0 deletions database/migrations/2025_01_31_140629_make_category_nullable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
public function up(): void
{
Schema::table('fob_tickets', function (Blueprint $table) {
$table->foreignId('category_id')->nullable()->change();
});
}

public function down(): void
{
Schema::table('fob_tickets', function (Blueprint $table) {
$table->foreignId('category_id')->change();
});
}
};
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"provider": "FriendsOfBotble\\Ticksify\\Providers\\TicksifyServiceProvider",
"author": "Friends Of Botble",
"url": "https://friendsofbotble.com",
"version": "1.0.0",
"version": "1.0.1",
"description": "Easily to manage and organize your customer support tickets.",
"minimum_core_version": "7.3.0"
}
2 changes: 2 additions & 0 deletions resources/views/themes/tickets/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@
<span class="fob-ticksify-ticket-detail">
<strong>{{ __('Status') }}:</strong> {!! $ticket->status->toHtml() !!}
</span>
@if ($ticket->category)
<span class="fob-ticksify-ticket-detail">
<strong>{{ __('Category') }}:</strong> {{ $ticket->category->name }}
@endif
</span>
<span class="fob-ticksify-ticket-detail">
<strong>{{ __('Created') }}:</strong> {{ $ticket->created_at->diffForHumans() }}
Expand Down
8 changes: 5 additions & 3 deletions resources/views/themes/tickets/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
</div>

@if(auth()->user()->hasPermission('fob-ticksify.tickets.messages.store'))
@if(auth()->check() && auth()->user()->hasPermission('fob-ticksify.tickets.messages.store'))
<div class="fob-ticksify-card">
<h5 class="fob-ticksify-card-title">{{ __('Reply to Ticket') }}</h5>
@if(! $ticket->is_locked)
Expand Down Expand Up @@ -87,8 +87,10 @@ class="fob-ticksify-message-time"
</dd>
<dt>{{ __('Priority') }}</dt>
<dd>{!! $ticket->priority->toHtml() !!}</dd>
<dt>{{ __('Category') }}</dt>
<dd>{{ $ticket->category->name }}</dd>
@if ($ticket->category)
<dt>{{ __('Category') }}</dt>
<dd>{{ $ticket->category->name }}</dd>
@endif
</dl>
</div>

Expand Down
6 changes: 4 additions & 2 deletions resources/views/tickets/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@
<dd class="col-7">#{{ $ticket->getKey() }}</dd>
<dt class="col-5">{{ trans('plugins/fob-ticksify::ticksify.priority') }}:</dt>
<dd class="col-7">{!! $ticket->priority->toHtml() !!}</dd>
<dt class="col-5">{{ trans('plugins/fob-ticksify::ticksify.category') }}:</dt>
<dd class="col-7">{{ $ticket->category->name }}</dd>
@if ($ticket->category)
<dt class="col-5">{{ trans('plugins/fob-ticksify::ticksify.category') }}:</dt>
<dd class="col-7">{{ $ticket->category->name }}</dd>
@endif
<dt class="col-5">{{ trans('plugins/fob-ticksify::ticksify.created_at') }}:</dt>
<dd class="col-7">
<time title="{{ $ticket->created_at->translatedFormat('d M Y H:i') }}">{{ $ticket->created_at->diffForHumans() }}</time>
Expand Down
6 changes: 5 additions & 1 deletion src/Forms/Fronts/TicketForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Botble\Theme\Facades\Theme;
use Botble\Theme\FormFront;
use FriendsOfBotble\Ticksify\Enums\TicketPriority;
use FriendsOfBotble\Ticksify\Http\Requests\Fronts\TicketRequest;
use FriendsOfBotble\Ticksify\Models\Category;
use FriendsOfBotble\Ticksify\Models\Ticket;

Expand All @@ -32,26 +33,29 @@ public function setup(): void
->model(Ticket::class)
->contentOnly()
->setUrl(route('fob-ticksify.public.tickets.store'))
->setValidatorClass(TicketRequest::class)
->add(
'title',
TextField::class,
TextFieldOption::make()
->label(__('Subject'))
->placeholder(__('Briefly describe your issue'))
->required()
)
->add(
'category_id',
SelectField::class,
SelectFieldOption::make()
->label(__('Category'))
->choices($categories),
->choices(['' => __('Uncategorized')] + $categories),
)
->add(
'trix-editor',
HtmlField::class,
HtmlFieldOption::make()
->label(__('Content'))
->content('<trix-editor input="content"></trix-editor>')
->required()
)
->add(
'content',
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Requests/Fronts/TicketRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public function rules(): array
{
return [
'title' => ['required', 'string', 'min:3', 'max:255'],
'category_id' => ['required', 'string', Rule::exists(Category::class, 'id')],
'content' => ['required', 'string', 'min:20', 'max:10000'],
'category_id' => ['nullable', Rule::exists(Category::class, 'id')],
'content' => ['required', 'string', 'max:100000'],
];
}
}
3 changes: 2 additions & 1 deletion src/Tables/TicketTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function setup(): void
LinkableColumn::make('category_id')
->label(trans('plugins/fob-ticksify::ticksify.category'))
->urlUsing(fn (LinkableColumn $column) => route('fob-ticksify.categories.edit', $column->getItem()->category_id))
->getValueUsing(fn (LinkableColumn $column) => $column->getItem()->category->name),
->getValueUsing(fn (LinkableColumn $column) => $column->getItem()->category?->name)
->withEmptyState(),
StatusColumn::make()->alignStart(),
DateTimeColumn::make('created_at'),
])
Expand Down

0 comments on commit e1bd23e

Please sign in to comment.