app/Http/Controllers/Student/ChildrenController.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)
    {
        $validator = Validator::make($request->all(), [
            'fname'                 => ['required', 'string', 'max:255'],
            'lname'                 => ['required', 'string', 'max:255'],
            'email'                 => ['required', 'unique:users', 'email', 'max:255'],
            'status'                => ['required', 'integer'],
            '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.children.create');
        }
        $data = $request->all();
        $user = User::create([
            'fname'                 => $data['fname'],
            'lname'                 => $data['lname'],
            'email'                 => $data['email'],
            'password'              => Auth::user()->password,
            'student_status_id'     => $data['status'],
            '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'],
            'grade_id'              => $data['grade_id'],
            'parent_fname'          => $data['parent_fname'],
            'parent_lname'          => $data['parent_lname'],
            'other_notes'           => $data['other_notes'],
            'school'                => $data['school'],
            'major_intersection'    => $data['major_intersection'],
            'parent_id'             => Auth::user()->id,
            'approved'              => 1,
            'status_id'             => 1
        ]);
        $role = Role::select('id')->where('name', 'Student')->first();
        $user->roles()->attach($role);
        foreach ($data['subjects'] as $subject) {
            $user -> subjects() -> attach($subject);
        }
        if ($user == NULL)
        {
             session() -> flash('error', "There is an error adding a children!");
             return redirect() -> route('student.children.create');
        }
        session() -> flash('success', "You have added a Children!");
        return redirect() -> route('student.children.index');
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'fname' => [ 'required' , 'string' , 'max:255' ] , 'lname' => [ 'required' , 'string' , 'max:255' ] , 'email' => [ 'required' , 'unique:users' , 'email' , 'max:255' ] , 'status' => [ 'required' , 'integer' ] , '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.children.create' ) ; } $ data = $ request -> all ( ) ; $ user = User :: create ( [ 'fname' => $ data [ 'fname' ] , 'lname' => $ data [ 'lname' ] , 'email' => $ data [ 'email' ] , 'password' => Auth :: user ( ) -> password , 'student_status_id' => $ data [ 'status' ] , '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' ] , 'grade_id' => $ data [ 'grade_id' ] , 'parent_fname' => $ data [ 'parent_fname' ] , 'parent_lname' => $ data [ 'parent_lname' ] , 'other_notes' => $ data [ 'other_notes' ] , 'school' => $ data [ 'school' ] , 'major_intersection' => $ data [ 'major_intersection' ] , 'parent_id' => Auth :: user ( ) -> id , 'approved' => 1 , 'status_id' => 1 ] ) ; $ role = Role :: select ( 'id' ) -> where ( 'name' , 'Student' ) -> first ( ) ; $ user -> roles ( ) -> attach ( $ role ) ; foreach ( $ data [ 'subjects' ] as $ subject ) { $ user -> subjects ( ) -> attach ( $ subject ) ; } if ( $ user == NULL ) { session ( ) -> flash ( 'error' , " There is an error adding a children! " ) ; return redirect ( ) -> route ( 'student.children.create' ) ; } session ( ) -> flash ( 'success' , " You have added a Children! " ) ; return redirect ( ) -> route ( 'student.children.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .