app/Http/Controllers/Admin/InvoicesController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Invoice  $Invoice
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Invoice $invoice)
    {
        $validator = Validator::make($request->all(), [
            'invoice_date'      => ['nullable', 'date'],
            'num_of_sessions'   => ['required', 'int'],
            'total_hours'       => ['required', 'string'],
            'total_amount'      => ['required', 'string'],
            'paid_amount'       => ['nullable', 'string'],
            'invoice_notes'     => ['nullable', 'string'],
            'status'            => ['nullable', 'string'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.invoices.edit', $invoice);
        }
        $data = $request->all();
        $invoice->invoice_date = $data['invoice_date'];
        $invoice->num_of_sessions = $data['num_of_sessions'];
        $invoice->total_hours = $data['total_hours'];
        $invoice->total_amount = $data['total_amount'];
        $invoice->paid_amount = $data['paid_amount'];
        $invoice->invoice_notes = $data['invoice_notes'];
        $invoice->status = $data['status'];
        if($invoice->save()){
            $request->session()->flash('success', 'You have modified invoices!');
            return redirect()->route('admin.invoices.index');
        }
        $request->session()->flash('error', 'There was an error modifying invoices');
        return redirect()->route('admin.invoices.edit', $invoice);
    }
public function update ( Request $ request , Invoice $ invoice ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'invoice_date' => [ 'nullable' , 'date' ] , 'num_of_sessions' => [ 'required' , 'int' ] , 'total_hours' => [ 'required' , 'string' ] , 'total_amount' => [ 'required' , 'string' ] , 'paid_amount' => [ 'nullable' , 'string' ] , 'invoice_notes' => [ 'nullable' , 'string' ] , 'status' => [ 'nullable' , 'string' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.invoices.edit' , $ invoice ) ; } $ data = $ request -> all ( ) ; $ invoice -> invoice_date = $ data [ 'invoice_date' ] ; $ invoice -> num_of_sessions = $ data [ 'num_of_sessions' ] ; $ invoice -> total_hours = $ data [ 'total_hours' ] ; $ invoice -> total_amount = $ data [ 'total_amount' ] ; $ invoice -> paid_amount = $ data [ 'paid_amount' ] ; $ invoice -> invoice_notes = $ data [ 'invoice_notes' ] ; $ invoice -> status = $ data [ 'status' ] ; if ( $ invoice -> save ( ) ) { $ request -> session ( ) -> flash ( 'success' , 'You have modified invoices!' ) ; return redirect ( ) -> route ( 'admin.invoices.index' ) ; } $ request -> session ( ) -> flash ( 'error' , 'There was an error modifying invoices' ) ; return redirect ( ) -> route ( 'admin.invoices.edit' , $ invoice ) ; }
Update the specified resource in storage.
Update the specified resource in storage .