user(); $query = Ticket::query() ->visibleTo($user) ->orderByDesc('id'); if ($request->filled('search')) { $search = addcslashes( (string) $request->query('search'), '%_\\' ); $query->where( 'subject', 'like', '%'.$search.'%' ); } return response()->json( $query->paginate(30) ); } public function show(Request $request, Ticket $ticket): JsonResponse { $user = $request->user(); $ticket = Ticket::query() ->visibleTo($user) ->whereKey($ticket->getKey()) ->firstOrFail(); return response()->json( $ticket->load([ 'comments', 'status', 'priority', 'category', 'project', 'team', 'agent', 'attachments', 'tags', ]) ); } public function store(Request $request): JsonResponse { $data = $request->validate([ 'subject' => [ 'required', 'string', 'max:255', ], 'body' => [ 'required', 'string', ], 'priority_id' => [ 'required', 'integer', Rule::exists('helpdesk_priorities', 'id'), ], 'category_id' => [ 'nullable', 'integer', Rule::exists('helpdesk_categories', 'id'), ], 'project_id' => [ 'nullable', 'integer', Rule::exists('helpdesk_projects', 'id'), ], 'product_id' => [ 'nullable', 'integer', Rule::exists('helpdesk_products', 'id'), ], 'team_id' => [ 'nullable', 'integer', Rule::exists('helpdesk_teams', 'id'), ], 'board_id' => [ 'nullable', 'integer', Rule::exists('helpdesk_kanban_boards', 'id'), ], 'due_at' => [ 'nullable', 'date', ], 'tag_ids' => [ 'sometimes', 'array', ], 'tag_ids.*' => [ 'integer', 'distinct', Rule::exists('helpdesk_tags', 'id'), ], 'attachments' => [ 'sometimes', 'array', ], 'attachments.*' => [ 'file', 'max:10240', ], ]); $files = $request->file('attachments', []); unset($data['attachments']); $ticket = $this->tickets->create( $request->user(), $data, $files ); return response()->json( $ticket, 201 ); } }