app/Http/Controllers/TicketController.php
/**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @param Ticket $ticket
     * @return Response
     */
Store a newly created resource in storage.
@param Request $request
@param Ticket $ticket
@return Response
Store a newly created resource in storage . @param Request $request @param Ticket $ticket @return Response
public function storeResponse(Request $request, Ticket $ticket)
    {
        $validatedData = $request->validate([
            'content' => 'required|max:2000',
            'attachments.*' => 'mimes:jpeg,png,jpg,bmp,txt,error,log|max:10000',
            'attachments' => 'files_count:5',
        ]);
        $validatedData['ticket_id'] = $ticket->id;
        $validatedData['author_id'] = auth()->id();
        $ticketResponse = TicketResponse::query()->create($validatedData);
        if ($request->file('attachments')) {
            foreach ($request->file('attachments') as $attachment) {
                $file = $attachment->store(Ticket::UPLOAD_PATH);
                TicketAttachment::query()->create([
                    'ticket_id' => $ticket->id,
                    'response_id' => $ticketResponse->id,
                    'name' => $attachment->getClientOriginalName(),
                    'url' => $file,
                ]);
            }
        }
        $ticket->status = Ticket::STATUS_READ_BY_USER;
        $ticket->save();
        session()->flash('success', trans('ticket.show.response.messages.success'));
        return redirect()->route('ticket.show', [$ticket]);
    }
public function storeResponse ( Request $ request , Ticket $ ticket ) { $ validatedData = $ request -> validate ( [ 'content' => 'required|max:2000' , 'attachments.*' => 'mimes:jpeg,png,jpg,bmp,txt,error,log|max:10000' , 'attachments' => 'files_count:5' , ] ) ; $ validatedData [ 'ticket_id' ] = $ ticket -> id ; $ validatedData [ 'author_id' ] = auth ( ) -> id ( ) ; $ ticketResponse = TicketResponse :: query ( ) -> create ( $ validatedData ) ; if ( $ request -> file ( 'attachments' ) ) { foreach ( $ request -> file ( 'attachments' ) as $ attachment ) { $ file = $ attachment -> store ( Ticket :: UPLOAD_PATH ) ; TicketAttachment :: query ( ) -> create ( [ 'ticket_id' => $ ticket -> id , 'response_id' => $ ticketResponse -> id , 'name' => $ attachment -> getClientOriginalName ( ) , 'url' => $ file , ] ) ; } } $ ticket -> status = Ticket :: STATUS_READ_BY_USER ; $ ticket -> save ( ) ; session ( ) -> flash ( 'success' , trans ( 'ticket.show.response.messages.success' ) ) ; return redirect ( ) -> route ( 'ticket.show' , [ $ ticket ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
/** @var TicketResponse $ticketResponse */ /** @var UploadedFile $attachment */