app/Http/Controllers/Admin/PaychequesController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Paycheque  $paycheque
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Paycheque $paycheque)
    {
        $validator = Validator::make($request->all(), [
            'paycheque_num'     => ['nullable', 'string'],
            'num_of_sessions'   => ['nullable', 'integer'],
            'total_hours'       => ['nullable', 'string'],
            'num_of_essays'     => ['nullable', 'integer'],
            'essay_amount'      => ['nullable', 'string'],
            'raise_amount'      => ['nullable', 'string'],
            'total_amount'      => ['required', 'string'],
            'paid_amount'       => ['nullable', 'string'],
            'paycheque_notes'   => ['nullable', 'string'],
            'status'            => ['nullable', 'string']
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->message()->first());
            return redirect()->route('admin.paycheques.edit');
        }
        $data = $request->all();
        if (isset($paycheque->paycheque_numm)) $paycheque->paycheque_num = $data['paycheque_num'];
        if (isset($paycheque->num_of_sessions)) $paycheque->num_of_sessions = $data['num_of_sessions'];
        if (isset($paycheque->total_hours)) $paycheque->total_hours = $data['total_hours'];
        if (isset($paycheque->num_of_essays)) $paycheque->num_of_essays = $data['num_of_essays'];
        if (isset($paycheque->essay_amount)) $paycheque->essay_amount = $data['essay_amount'];
        if (isset($paycheque->raise_amount)) $paycheque->raise_amount = $data['raise_amount'];
        $paycheque->total_amount = $data['total_amount'];
        if (isset($paycheque->paid_amount)) $paycheque->paid_amount = $data['paid_amount'];
        if (isset($paycheque->paycheque_notes)) $paycheque->paycheque_notes = $data['paycheque_notes'];
        if (isset($paycheque->status)) $paycheque->status = $data['status'];
        if (!$paycheque->save())
        {
            $request->session()->flash('error', 'There is an error modifying paycheque!');
            return redirect()->route('admin.paycheques.edit');
        }
        $request->session()->flash('success', 'You have modified paycheque details!');
        return redirect()->route('admin.paycheques.index');
    }
public function update ( Request $ request , Paycheque $ paycheque ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'paycheque_num' => [ 'nullable' , 'string' ] , 'num_of_sessions' => [ 'nullable' , 'integer' ] , 'total_hours' => [ 'nullable' , 'string' ] , 'num_of_essays' => [ 'nullable' , 'integer' ] , 'essay_amount' => [ 'nullable' , 'string' ] , 'raise_amount' => [ 'nullable' , 'string' ] , 'total_amount' => [ 'required' , 'string' ] , 'paid_amount' => [ 'nullable' , 'string' ] , 'paycheque_notes' => [ 'nullable' , 'string' ] , 'status' => [ 'nullable' , 'string' ] ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> message ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.paycheques.edit' ) ; } $ data = $ request -> all ( ) ; if ( isset ( $ paycheque -> paycheque_numm ) ) $ paycheque -> paycheque_num = $ data [ 'paycheque_num' ] ; if ( isset ( $ paycheque -> num_of_sessions ) ) $ paycheque -> num_of_sessions = $ data [ 'num_of_sessions' ] ; if ( isset ( $ paycheque -> total_hours ) ) $ paycheque -> total_hours = $ data [ 'total_hours' ] ; if ( isset ( $ paycheque -> num_of_essays ) ) $ paycheque -> num_of_essays = $ data [ 'num_of_essays' ] ; if ( isset ( $ paycheque -> essay_amount ) ) $ paycheque -> essay_amount = $ data [ 'essay_amount' ] ; if ( isset ( $ paycheque -> raise_amount ) ) $ paycheque -> raise_amount = $ data [ 'raise_amount' ] ; $ paycheque -> total_amount = $ data [ 'total_amount' ] ; if ( isset ( $ paycheque -> paid_amount ) ) $ paycheque -> paid_amount = $ data [ 'paid_amount' ] ; if ( isset ( $ paycheque -> paycheque_notes ) ) $ paycheque -> paycheque_notes = $ data [ 'paycheque_notes' ] ; if ( isset ( $ paycheque -> status ) ) $ paycheque -> status = $ data [ 'status' ] ; if ( ! $ paycheque -> save ( ) ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error modifying paycheque!' ) ; return redirect ( ) -> route ( 'admin.paycheques.edit' ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have modified paycheque details!' ) ; return redirect ( ) -> route ( 'admin.paycheques.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .