app/Http/Controllers/Admin/TutorsController.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)
    {
        if (Gate::denies('manage-tutors')) {
            return redirect(route('admin.tutors.create'));
        }
        $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.create');
        }
        $data = $request->all();
        $tutor = User::create([
            'fname'                 => $data['fname'],
            'lname'                 => $data['lname'],
            'email'                 => $data['email'],
            'password'              => Hash::make($data['password']),
            'home_phone'            => $data['home_phone'],
            'cell_phone'            => $data['cell_phone'],
            'address'               => $data['address'],
            'city'                  => $data['city'],
            'state_id'              => $data['state_id'],
            'pcode'                 => $data['pcode'],
            'country_id'            => $data['country_id'],
            'other_notes'           => $data['other_notes'],
            'post_secondary_edu'    => $data['post_secondary_edu'],
            'subjects_studied'      => $data['subjects_studied'],
            'tutoring_courses'      => $data['tutoring_courses'],
            'work_experience'       => $data['work_experience'],
            'tutoring_areas'        => $data['tutoring_areas'],
            'references'            => $data['references'],
            'gender'                => $data['gender'],
            'certified_teacher'     => $data['certified_teacher'],
            'criminal_record'       => $data['criminal_record'],
            'criminal_check'        => $data['criminal_check'],
            'approved'              => $data['approved'],
            'status'                => $data['status'],
        ]);
        if ($tutor != NULL){
            $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.create');
        }
        return redirect()->route('admin.tutors.index');
    }
public function store ( Request $ request ) { if ( Gate :: denies ( 'manage-tutors' ) ) { return redirect ( route ( 'admin.tutors.create' ) ) ; } $ 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.create' ) ; } $ data = $ request -> all ( ) ; $ tutor = User :: create ( [ 'fname' => $ data [ 'fname' ] , 'lname' => $ data [ 'lname' ] , 'email' => $ data [ 'email' ] , 'password' => Hash :: make ( $ data [ 'password' ] ) , 'home_phone' => $ data [ 'home_phone' ] , 'cell_phone' => $ data [ 'cell_phone' ] , 'address' => $ data [ 'address' ] , 'city' => $ data [ 'city' ] , 'state_id' => $ data [ 'state_id' ] , 'pcode' => $ data [ 'pcode' ] , 'country_id' => $ data [ 'country_id' ] , 'other_notes' => $ data [ 'other_notes' ] , 'post_secondary_edu' => $ data [ 'post_secondary_edu' ] , 'subjects_studied' => $ data [ 'subjects_studied' ] , 'tutoring_courses' => $ data [ 'tutoring_courses' ] , 'work_experience' => $ data [ 'work_experience' ] , 'tutoring_areas' => $ data [ 'tutoring_areas' ] , 'references' => $ data [ 'references' ] , 'gender' => $ data [ 'gender' ] , 'certified_teacher' => $ data [ 'certified_teacher' ] , 'criminal_record' => $ data [ 'criminal_record' ] , 'criminal_check' => $ data [ 'criminal_check' ] , 'approved' => $ data [ 'approved' ] , 'status' => $ data [ 'status' ] , ] ) ; if ( $ tutor != NULL ) { $ 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.create' ) ; } return redirect ( ) -> route ( 'admin.tutors.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .