app/Http/Controllers/ExpenseController.php
/**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @return JsonResponse
     */
Store a newly created resource in storage.
@param Request $request
@return JsonResponse
Store a newly created resource in storage . @param Request $request @return JsonResponse
public function store(Request $request)
    {
        $request->validate(
            [
                'branch_id' => 'required|exists:branches,id',
                'amount' => 'required|numeric',
                'reason' => 'required'
            ]
        );
        $expense = new Expense();
        $expense->branch_id = $request->branch_id;
        $expense->amount = $request->amount;
        $expense->reason = $request->reason;
        if ($expense->save()) {
            return Helper::response_with_data($expense, false);
        }
        return Helper::response_with_data(null, true);
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'branch_id' => 'required|exists:branches,id' , 'amount' => 'required|numeric' , 'reason' => 'required' ] ) ; $ expense = new Expense ( ) ; $ expense -> branch_id = $ request -> branch_id ; $ expense -> amount = $ request -> amount ; $ expense -> reason = $ request -> reason ; if ( $ expense -> save ( ) ) { return Helper :: response_with_data ( $ expense , false ) ; } return Helper :: response_with_data ( null , true ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .