app/Http/Controllers/Admin/TutorsController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\User  $user
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, User $tutor)
    {
        if (Gate::denies('manage-tutors')) {
            return redirect(route('admin.tutors.edit', $tutor));
        }
        $validator = Validator::make($request->all(), [
            'fname'                 => ['required', 'string', 'max:255'],
            'lname'                 => ['required', 'string', 'max:255'],
            'email'                 => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password'              => ['required', 'string', 'min:1', 'confirmed'],
            'home_phone'            => ['required', 'string'],
            'cell_phone'            => ['nullable', 'string'],
            'address'               => ['required', 'string'],
            'city'                  => ['required', 'string'],
            'state_id'              => ['required', 'integer'],
            'pcode'                 => ['required', 'string'],
            'country_id'            => ['required', 'integer'],
            'other_notes'           => ['required', 'string'],
            'post_secondary_edu'    => ['required', 'string'],
            'subjects_studied'      => ['required', 'string'],
            'tutoring_courses'      => ['required', 'string'],
            'work_experience'       => ['required', 'string'],
            'tutoring_areas'        => ['required', 'string'],
            'references'            => ['required', 'string'],
            'gender'                => ['nullable', 'string'],
            'certified_teacher'     => ['required', 'string'],
            'criminal_record'       => ['required', 'string'],
            'criminal_check'        => ['required', 'string'],
            'approved'              => ['nullable', 'integer'],
            'status'                => ['nullable', 'integer'],
        ]);
        if ($validator->fails())
        {
            session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.tutors.edit', $tutor);
        }
        $data = $request->all();
        $tutor->fname = $data['fname'];
        $tutor->lname = $data['lname'];
        $tutor->email = $data['email'];
        $tutor->password = Hash::make($data['password']);
        $tutor->home_phone = $data['home_phone'];
        $tutor->cell_phone = $data['cell_phone'];
        $tutor->address = $data['address'];
        $tutor->city = $data['city'];
        $tutor->state_id = $data['state_id'];
        $tutor->pcode = $data['pcode'];
        $tutor->country_id = $data['country_id'];
        $tutor->other_notes = $data['other_notes'];
        $tutor->post_secondary_edu = $data['post_secondary_edu'];
        $tutor->subjects_studied = $data['subjects_studied'];
        $tutor->tutoring_courses = $data['tutoring_courses'];
        $tutor->work_experience = $data['work_experience'];
        $tutor->tutoring_areas = $data['tutoring_areas'];
        $tutor->references = $data['references'];
        $tutor->gender = $data['gender'];
        $tutor->certified_teacher = $data['certified_teacher'];
        $tutor->criminal_record = $data['criminal_record'];
        $tutor->criminal_check = $data['criminal_check'];
        $tutor->approved = $data['approved'];
        $tutor->status = $data['status'];
        if ($tutor->save()){
            $request->session()->flash('success', $tutor->fname . ' ' . $tutor->lname .' has been updated');
        } else {
            $request->session()->flash('error', 'There was an error updating the tutor');
            return redirect()->route('admin.tutors.edit', $tutor);
        }
        return redirect()->route('admin.tutors.index');
    }
public function update ( Request $ request , User $ tutor ) { if ( Gate :: denies ( 'manage-tutors' ) ) { return redirect ( route ( 'admin.tutors.edit' , $ tutor ) ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'fname' => [ 'required' , 'string' , 'max:255' ] , 'lname' => [ 'required' , 'string' , 'max:255' ] , 'email' => [ 'required' , 'string' , 'email' , 'max:255' , 'unique:users' ] , 'password' => [ 'required' , 'string' , 'min:1' , 'confirmed' ] , 'home_phone' => [ 'required' , 'string' ] , 'cell_phone' => [ 'nullable' , 'string' ] , 'address' => [ 'required' , 'string' ] , 'city' => [ 'required' , 'string' ] , 'state_id' => [ 'required' , 'integer' ] , 'pcode' => [ 'required' , 'string' ] , 'country_id' => [ 'required' , 'integer' ] , 'other_notes' => [ 'required' , 'string' ] , 'post_secondary_edu' => [ 'required' , 'string' ] , 'subjects_studied' => [ 'required' , 'string' ] , 'tutoring_courses' => [ 'required' , 'string' ] , 'work_experience' => [ 'required' , 'string' ] , 'tutoring_areas' => [ 'required' , 'string' ] , 'references' => [ 'required' , 'string' ] , 'gender' => [ 'nullable' , 'string' ] , 'certified_teacher' => [ 'required' , 'string' ] , 'criminal_record' => [ 'required' , 'string' ] , 'criminal_check' => [ 'required' , 'string' ] , 'approved' => [ 'nullable' , 'integer' ] , 'status' => [ 'nullable' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.tutors.edit' , $ tutor ) ; } $ data = $ request -> all ( ) ; $ tutor -> fname = $ data [ 'fname' ] ; $ tutor -> lname = $ data [ 'lname' ] ; $ tutor -> email = $ data [ 'email' ] ; $ tutor -> password = Hash :: make ( $ data [ 'password' ] ) ; $ tutor -> home_phone = $ data [ 'home_phone' ] ; $ tutor -> cell_phone = $ data [ 'cell_phone' ] ; $ tutor -> address = $ data [ 'address' ] ; $ tutor -> city = $ data [ 'city' ] ; $ tutor -> state_id = $ data [ 'state_id' ] ; $ tutor -> pcode = $ data [ 'pcode' ] ; $ tutor -> country_id = $ data [ 'country_id' ] ; $ tutor -> other_notes = $ data [ 'other_notes' ] ; $ tutor -> post_secondary_edu = $ data [ 'post_secondary_edu' ] ; $ tutor -> subjects_studied = $ data [ 'subjects_studied' ] ; $ tutor -> tutoring_courses = $ data [ 'tutoring_courses' ] ; $ tutor -> work_experience = $ data [ 'work_experience' ] ; $ tutor -> tutoring_areas = $ data [ 'tutoring_areas' ] ; $ tutor -> references = $ data [ 'references' ] ; $ tutor -> gender = $ data [ 'gender' ] ; $ tutor -> certified_teacher = $ data [ 'certified_teacher' ] ; $ tutor -> criminal_record = $ data [ 'criminal_record' ] ; $ tutor -> criminal_check = $ data [ 'criminal_check' ] ; $ tutor -> approved = $ data [ 'approved' ] ; $ tutor -> status = $ data [ 'status' ] ; if ( $ tutor -> save ( ) ) { $ request -> session ( ) -> flash ( 'success' , $ tutor -> fname . ' ' . $ tutor -> lname . ' has been updated' ) ; } else { $ request -> session ( ) -> flash ( 'error' , 'There was an error updating the tutor' ) ; return redirect ( ) -> route ( 'admin.tutors.edit' , $ tutor ) ; } return redirect ( ) -> route ( 'admin.tutors.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .