app/Http/Controllers/LoanController.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)
    {
        $input = $request->all();
        $validate = Validator::make($input, [
            'type' => 'required',
            'duration' => 'required',
            'amount' => 'required',
            'surety' => 'required',
            'member' => 'required',
            'mode' => 'required',
        ]);
        if($validate->fails()) {
            return back()->with('error', 'Please fill all fields.');
        }
        $member = Member::find($request->member);
        $date = Setting::find(1)->pDate;
        $loan = Loan::create([
            'member_id' => $request->member,
            'duration' => $request->duration,
            'loan_type' => $request->type,
            'amount' => $request->amount,
            'balance' => $request->amount,
            'lpDate' => $date,
            'refer1' => $request->surety[0],
            'refer2' => $request->surety[1],
            'granted_by' => Auth::id(),
            'mode' => $request->mode,
        ]);
        if ($loan) {
            return redirect()->back()->with('suc', 'Loan approved successfully');
        } else {
            return redirect()->back()->with('err', 'Loan approval failed, please refresh page and try again');
        }
    }
public function store ( Request $ request ) { $ input = $ request -> all ( ) ; $ validate = Validator :: make ( $ input , [ 'type' => 'required' , 'duration' => 'required' , 'amount' => 'required' , 'surety' => 'required' , 'member' => 'required' , 'mode' => 'required' , ] ) ; if ( $ validate -> fails ( ) ) { return back ( ) -> with ( 'error' , 'Please fill all fields.' ) ; } $ member = Member :: find ( $ request -> member ) ; $ date = Setting :: find ( 1 ) -> pDate ; $ loan = Loan :: create ( [ 'member_id' => $ request -> member , 'duration' => $ request -> duration , 'loan_type' => $ request -> type , 'amount' => $ request -> amount , 'balance' => $ request -> amount , 'lpDate' => $ date , 'refer1' => $ request -> surety [ 0 ] , 'refer2' => $ request -> surety [ 1 ] , 'granted_by' => Auth :: id ( ) , 'mode' => $ request -> mode , ] ) ; if ( $ loan ) { return redirect ( ) -> back ( ) -> with ( 'suc' , 'Loan approved successfully' ) ; } else { return redirect ( ) -> back ( ) -> with ( 'err' , 'Loan approval failed, please refresh page and try again' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .