app/Http/Controllers/Admin/ExpensesController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Expense  $expense
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Expense $expense)
    {
        $validator = Validator::make($request->all(), [
            'e_name'        => ['required', 'string'],
            'expense_date'  => ['required', 'date'],
            'amount'        => ['required', 'string'],
            'notes'         => ['nullable', 'string'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.expenses.edit', $expense);
        }
        $data = $request->all();
        $expense->name = $data['e_name'];
        $expense->date = $data['expense_date'];
        $expense->amount = $data['amount'];
        if (isset($data['notes'])) $expense->detail = $data['notes'];
        if(!$expense->save()) {
            $request->session()->flash('error', 'There is an error updating the Expense details');
            return redirect()->route('admin.expenses.edit', $expense);
        }
        $request->session()->flash('success', 'Expense details have been successfully updated');
        return redirect()->route('admin.expenses.index');
    }
public function update ( Request $ request , Expense $ expense ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'e_name' => [ 'required' , 'string' ] , 'expense_date' => [ 'required' , 'date' ] , 'amount' => [ 'required' , 'string' ] , 'notes' => [ 'nullable' , 'string' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.expenses.edit' , $ expense ) ; } $ data = $ request -> all ( ) ; $ expense -> name = $ data [ 'e_name' ] ; $ expense -> date = $ data [ 'expense_date' ] ; $ expense -> amount = $ data [ 'amount' ] ; if ( isset ( $ data [ 'notes' ] ) ) $ expense -> detail = $ data [ 'notes' ] ; if ( ! $ expense -> save ( ) ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error updating the Expense details' ) ; return redirect ( ) -> route ( 'admin.expenses.edit' , $ expense ) ; } $ request -> session ( ) -> flash ( 'success' , 'Expense details have been successfully updated' ) ; return redirect ( ) -> route ( 'admin.expenses.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .