app/Http/Controllers/Admin/AssignmentsController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Assignment  $assignment
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Assignment $assignment)
    {
        if (Gate::denies('manage-students')) return redirect()->route('admin.assignments.index');
        $validator = Validator::make($request->all(), [
            'tutor_val'         => ['required', 'integer'],
            'student_val'       => ['required', 'integer'],
            'base_invoice'      => ['required', 'string'],
            'base_wage'         => ['required', 'string'],
            'subjects'          => ['nullable', 'Array'],
            'active'            => ['nullable', 'integer']
        ]);
        if ($validator->fails())
        {
            session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.assignments.edit', $assignment);
        }
        $assignment->tutor_id = $request->tutor_val;
        $assignment->student_id =$request->student_val;
        $assignment->base_wage = $request->base_wage;
        $assignment->base_invoice = $request->base_invoice;
        $assignment->active = $request->active;
        $assignment->subjects()->sync($request->subjects);
        if (!$assignment->save()){
            $request->session()->flash('error', 'There was an error updating the assignment');
            return redirect()->route('admin.assignments.edit', $assignment);
        }
        $request->session()->flash('success', 'The assignment has been updated successfully');
        return redirect()->route('admin.assignments.index');
    }
public function update ( Request $ request , Assignment $ assignment ) { if ( Gate :: denies ( 'manage-students' ) ) return redirect ( ) -> route ( 'admin.assignments.index' ) ; $ validator = Validator :: make ( $ request -> all ( ) , [ 'tutor_val' => [ 'required' , 'integer' ] , 'student_val' => [ 'required' , 'integer' ] , 'base_invoice' => [ 'required' , 'string' ] , 'base_wage' => [ 'required' , 'string' ] , 'subjects' => [ 'nullable' , 'Array' ] , 'active' => [ 'nullable' , 'integer' ] ] ) ; if ( $ validator -> fails ( ) ) { session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.assignments.edit' , $ assignment ) ; } $ assignment -> tutor_id = $ request -> tutor_val ; $ assignment -> student_id = $ request -> student_val ; $ assignment -> base_wage = $ request -> base_wage ; $ assignment -> base_invoice = $ request -> base_invoice ; $ assignment -> active = $ request -> active ; $ assignment -> subjects ( ) -> sync ( $ request -> subjects ) ; if ( ! $ assignment -> save ( ) ) { $ request -> session ( ) -> flash ( 'error' , 'There was an error updating the assignment' ) ; return redirect ( ) -> route ( 'admin.assignments.edit' , $ assignment ) ; } $ request -> session ( ) -> flash ( 'success' , 'The assignment has been updated successfully' ) ; return redirect ( ) -> route ( 'admin.assignments.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .