app/Http/Controllers/Admin/ExpensesController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $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.create');
        }
        $data = $request->all();
        if (!isset($data['notes'])) $data['notes'] = '';
        $expense = Expense::create([
            'name'              => $data['e_name'],
            'date'              => $data['expense_date'],
            'amount'            => $data['amount'],
            'detail'            => $data['notes'],
        ]);
        if($expense == NULL) {
            $request->session()->flash('error', 'There is an error creating the Expense details');
            return redirect()->route('admin.expenses.create');
        }
        $request->session()->flash('success', 'Expense details have been successfully created');
        return redirect()->route('admin.expenses.index');
    }
public function store ( Request $ request ) { $ 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.create' ) ; } $ data = $ request -> all ( ) ; if ( ! isset ( $ data [ 'notes' ] ) ) $ data [ 'notes' ] = '' ; $ expense = Expense :: create ( [ 'name' => $ data [ 'e_name' ] , 'date' => $ data [ 'expense_date' ] , 'amount' => $ data [ 'amount' ] , 'detail' => $ data [ 'notes' ] , ] ) ; if ( $ expense == NULL ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error creating the Expense details' ) ; return redirect ( ) -> route ( 'admin.expenses.create' ) ; } $ request -> session ( ) -> flash ( 'success' , 'Expense details have been successfully created' ) ; return redirect ( ) -> route ( 'admin.expenses.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .