app/Http/Controllers/PaymentController.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)
    {
        try {
            $validator = Validator::make($request->all(),[
                'title' => 'required|unique:payments',
            ]);
            if ($validator->fails()) {
                return redirect()->back()->withErrors($validator)->withInput();
            }    
            $data = $request->all();
            $data['created_by'] = auth()->user()->id??null;
            Payment::create($data);
            return redirect(route('payments.index'))->withSuccess('Payment Added Successfully!');
        } catch (Exception $e) {
            return redirect()->back()->withDanger($e->getMessage());
        }
    }
public function store ( Request $ request ) { try { $ validator = Validator :: make ( $ request -> all ( ) , [ 'title' => 'required|unique:payments' , ] ) ; if ( $ validator -> fails ( ) ) { return redirect ( ) -> back ( ) -> withErrors ( $ validator ) -> withInput ( ) ; } $ data = $ request -> all ( ) ; $ data [ 'created_by' ] = auth ( ) -> user ( ) -> id ?? null ; Payment :: create ( $ data ) ; return redirect ( route ( 'payments.index' ) ) -> withSuccess ( 'Payment Added Successfully!' ) ; } catch ( Exception $ e ) { return redirect ( ) -> back ( ) -> withDanger ( $ e -> getMessage ( ) ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .