app/Http/Controllers/TicketController.php
/**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @return Response
     */
Store a newly created resource in storage.
@param Request $request
@return Response
Store a newly created resource in storage . @param Request $request @return Response
public function store(Request $request)
    {
        $validatedData = $request->validate([
            'category_id' => 'required|int',
            'title' => 'required|max:255',
            'content' => 'required|max:2000',
            'attachments.*' => 'mimes:jpeg,png,jpg,bmp,txt,error,log|max:10000',
            'attachments' => 'files_count:5',
        ]);
        $validatedData['author_id'] = auth()->id();
        $validatedData['status'] = Ticket::STATUS_OPEN;
        $ticket = Ticket::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,
                    'name' => $attachment->getClientOriginalName(),
                    'url' => $file,
                ]);
            }
        }
        session()->flash('success', trans('ticket.create.messages.success'));
        return redirect()->route('ticket.index');
    }
public function store ( Request $ request ) { $ validatedData = $ request -> validate ( [ 'category_id' => 'required|int' , 'title' => 'required|max:255' , 'content' => 'required|max:2000' , 'attachments.*' => 'mimes:jpeg,png,jpg,bmp,txt,error,log|max:10000' , 'attachments' => 'files_count:5' , ] ) ; $ validatedData [ 'author_id' ] = auth ( ) -> id ( ) ; $ validatedData [ 'status' ] = Ticket :: STATUS_OPEN ; $ ticket = Ticket :: 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 , 'name' => $ attachment -> getClientOriginalName ( ) , 'url' => $ file , ] ) ; } } session ( ) -> flash ( 'success' , trans ( 'ticket.create.messages.success' ) ) ; return redirect ( ) -> route ( 'ticket.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
/** @var Ticket $ticket */ /** @var UploadedFile $attachment */