app/Http/Controllers/Student/MyProfileController.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 $myprofile)
    {
        $validator = Validator::make($request->all(), [
            'fname'                 => ['required', 'string', 'max:255'],
            'lname'                 => ['required', 'string', 'max:255'],
            'email'                 => ['required', 'email', 'max:255'],
            'password'              => ['required', 'string', 'min:8', 'confirmed'],
            'home_phone'            => ['required', 'string'],
            'cell_phone'            => ['required', 'string'],
            'address'               => ['required', 'string'],
            'city'                  => ['required', 'string'],
            'state_id'              => ['required', 'integer'],
            'pcode'                 => ['required', 'string'],
            'country_id'            => ['required', 'integer'],
            'grade_id'              => ['required', 'integer'],
            'subjects'              => ['required'],
            'parent_fname'          => ['required', 'string'],
            'parent_lname'          => ['required', 'string'],
            'other_notes'           => ['required', 'string'],
            'school'                => ['required', 'string'],
            'major_intersection'    => ['required', 'string']
        ]);
        if ($validator->fails()) {
            session()->flash('error', $validator -> messages() -> first());
            return redirect()->route('student.myprofile.index');
        }
        $data = $request->all();
        $myprofile-> email = $data['email'];
        $myprofile-> password = Hash::make($data['password']);
        $myprofile-> fname = $data['fname'];
        $myprofile-> lname = $data['lname'];
        $myprofile-> grade_id = $data['grade_id'];
        $myprofile-> parent_fname = $data['parent_fname'];
        $myprofile-> parent_lname = $data['parent_lname'];
        $myprofile-> home_phone = $data['home_phone'];
        $myprofile-> cell_phone = $data['cell_phone'];
        $myprofile-> address = $data['address'];
        $myprofile-> city = $data['city'];
        $myprofile-> state_id = $data['state_id'];
        $myprofile-> pcode = $data['pcode'];
        $myprofile-> country_id = $data['country_id'];
        $myprofile-> other_notes = $data['other_notes'];
        foreach ($data['subjects'] as $subject) {
            $myprofile -> subjects() -> attach($subject);
        }
        if (!$myprofile->save())
        {
            session()->flash('error', "There is an error modifying student!");
        }
        session()->flash('success', "You have modified student!");
        return redirect()->route('student.myprofile.index');
    }
public function update ( Request $ request , User $ myprofile ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'fname' => [ 'required' , 'string' , 'max:255' ] , 'lname' => [ 'required' , 'string' , 'max:255' ] , 'email' => [ 'required' , 'email' , 'max:255' ] , 'password' => [ 'required' , 'string' , 'min:8' , 'confirmed' ] , 'home_phone' => [ 'required' , 'string' ] , 'cell_phone' => [ 'required' , 'string' ] , 'address' => [ 'required' , 'string' ] , 'city' => [ 'required' , 'string' ] , 'state_id' => [ 'required' , 'integer' ] , 'pcode' => [ 'required' , 'string' ] , 'country_id' => [ 'required' , 'integer' ] , 'grade_id' => [ 'required' , 'integer' ] , 'subjects' => [ 'required' ] , 'parent_fname' => [ 'required' , 'string' ] , 'parent_lname' => [ 'required' , 'string' ] , 'other_notes' => [ 'required' , 'string' ] , 'school' => [ 'required' , 'string' ] , 'major_intersection' => [ 'required' , 'string' ] ] ) ; if ( $ validator -> fails ( ) ) { session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'student.myprofile.index' ) ; } $ data = $ request -> all ( ) ; $ myprofile -> email = $ data [ 'email' ] ; $ myprofile -> password = Hash :: make ( $ data [ 'password' ] ) ; $ myprofile -> fname = $ data [ 'fname' ] ; $ myprofile -> lname = $ data [ 'lname' ] ; $ myprofile -> grade_id = $ data [ 'grade_id' ] ; $ myprofile -> parent_fname = $ data [ 'parent_fname' ] ; $ myprofile -> parent_lname = $ data [ 'parent_lname' ] ; $ myprofile -> home_phone = $ data [ 'home_phone' ] ; $ myprofile -> cell_phone = $ data [ 'cell_phone' ] ; $ myprofile -> address = $ data [ 'address' ] ; $ myprofile -> city = $ data [ 'city' ] ; $ myprofile -> state_id = $ data [ 'state_id' ] ; $ myprofile -> pcode = $ data [ 'pcode' ] ; $ myprofile -> country_id = $ data [ 'country_id' ] ; $ myprofile -> other_notes = $ data [ 'other_notes' ] ; foreach ( $ data [ 'subjects' ] as $ subject ) { $ myprofile -> subjects ( ) -> attach ( $ subject ) ; } if ( ! $ myprofile -> save ( ) ) { session ( ) -> flash ( 'error' , " There is an error modifying student! " ) ; } session ( ) -> flash ( 'success' , " You have modified student! " ) ; return redirect ( ) -> route ( 'student.myprofile.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .