app/Http/Controllers/Admin/StudentsController.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 $student)
    {
        $validator = Validator::make($request->all(), [
            'fname'                 => ['required', 'string', 'max:255'],
            'lname'                 => ['required', 'string', 'max:255'],
            'email'                 => ['required', 'email', 'max:255'],
            'password'              => ['nullable', 'string', 'min:8', 'confirmed'],
            'grade_id'              => ['required', 'integer'],
            'subjects'              => ['required', 'Array'],
            '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'],
            'parent_fname'          => ['required', 'string'],
            'parent_lname'          => ['required', 'string'],
            'service_method'        => ['required', 'string'],
            'other_notes'           => ['nullable', 'string'],
            'school'                => ['required', 'string'],
            'major_intersection'    => ['required', 'string'],
            'referrer_id'           => ['nullable', 'integer'],
            'student_status_id'     => ['nullable', 'integer'],
            'approved'              => ['nullable', 'integer'],
            'status'                => ['nullable', 'integer'],
        ]);
        if ($validator->fails()) {
            session()->flash('error', $validator -> messages() -> first());
            return redirect()->route('admin.students.edit', $student);
        }
        $data = $request->all();
        $student-> email = $data['email'];
        if ($data['password']) {
            $student-> password = Hash::make($data['password']);
        }        
        $student-> fname = $data['fname'];
        $student-> lname = $data['lname'];
        $student-> grade_id = $data['grade_id'];
        $student-> parent_fname = $data['parent_fname'];
        $student-> parent_lname = $data['parent_lname'];
        $student-> home_phone = $data['home_phone'];
        $student-> cell_phone = $data['cell_phone'];
        $student-> address = $data['address'];
        $student-> city = $data['city'];
        $student-> state_id = $data['state_id'];
        $student-> pcode = $data['pcode'];
        $student-> country_id = $data['country_id'];
        $student-> service_method = $data['service_method'];
        $student-> other_notes = $data['other_notes'];
        $student-> major_intersection = $data['major_intersection'];
        $student-> school = $data['school'];
        $student-> referrer_id = $data['referrer_id'];
        $student-> student_status_id = $data['student_status_id'];
        $student-> approved = $data['approved'];
        $student-> status = $data['status'];
        $student-> subjects() -> sync($data['subjects']);
        if (!$student->save())
        {
            session()->flash('error', "There is an error modifying student!");
            return redirect()->route('admin.students.edit', $student);
        }
        ActivityLog::log_activity(Auth::user()->id, "Profile Updated", "Student profile details updated.");
        session()->flash('success', "You have modified student!");
        return redirect()->route('admin.students.index');
    }
public function update ( Request $ request , User $ student ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'fname' => [ 'required' , 'string' , 'max:255' ] , 'lname' => [ 'required' , 'string' , 'max:255' ] , 'email' => [ 'required' , 'email' , 'max:255' ] , 'password' => [ 'nullable' , 'string' , 'min:8' , 'confirmed' ] , 'grade_id' => [ 'required' , 'integer' ] , 'subjects' => [ 'required' , 'Array' ] , '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' ] , 'parent_fname' => [ 'required' , 'string' ] , 'parent_lname' => [ 'required' , 'string' ] , 'service_method' => [ 'required' , 'string' ] , 'other_notes' => [ 'nullable' , 'string' ] , 'school' => [ 'required' , 'string' ] , 'major_intersection' => [ 'required' , 'string' ] , 'referrer_id' => [ 'nullable' , 'integer' ] , 'student_status_id' => [ 'nullable' , 'integer' ] , 'approved' => [ 'nullable' , 'integer' ] , 'status' => [ 'nullable' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.students.edit' , $ student ) ; } $ data = $ request -> all ( ) ; $ student -> email = $ data [ 'email' ] ; if ( $ data [ 'password' ] ) { $ student -> password = Hash :: make ( $ data [ 'password' ] ) ; } $ student -> fname = $ data [ 'fname' ] ; $ student -> lname = $ data [ 'lname' ] ; $ student -> grade_id = $ data [ 'grade_id' ] ; $ student -> parent_fname = $ data [ 'parent_fname' ] ; $ student -> parent_lname = $ data [ 'parent_lname' ] ; $ student -> home_phone = $ data [ 'home_phone' ] ; $ student -> cell_phone = $ data [ 'cell_phone' ] ; $ student -> address = $ data [ 'address' ] ; $ student -> city = $ data [ 'city' ] ; $ student -> state_id = $ data [ 'state_id' ] ; $ student -> pcode = $ data [ 'pcode' ] ; $ student -> country_id = $ data [ 'country_id' ] ; $ student -> service_method = $ data [ 'service_method' ] ; $ student -> other_notes = $ data [ 'other_notes' ] ; $ student -> major_intersection = $ data [ 'major_intersection' ] ; $ student -> school = $ data [ 'school' ] ; $ student -> referrer_id = $ data [ 'referrer_id' ] ; $ student -> student_status_id = $ data [ 'student_status_id' ] ; $ student -> approved = $ data [ 'approved' ] ; $ student -> status = $ data [ 'status' ] ; $ student -> subjects ( ) -> sync ( $ data [ 'subjects' ] ) ; if ( ! $ student -> save ( ) ) { session ( ) -> flash ( 'error' , " There is an error modifying student! " ) ; return redirect ( ) -> route ( 'admin.students.edit' , $ student ) ; } ActivityLog :: log_activity ( Auth :: user ( ) -> id , " Profile Updated " , " Student profile details updated. " ) ; session ( ) -> flash ( 'success' , " You have modified student! " ) ; return redirect ( ) -> route ( 'admin.students.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .