app/Http/Controllers/Admin/UsersController.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-users')) return redirect()->route('admin.users.create');
        $data = $request->all();
        $validator = Validator::make($data, [
            'fname'         => ['required', 'string', 'max:255'],
            'lname'         => ['required', 'string', 'max:255'],
            'email'         => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password'      => ['required', 'string', 'min:8', 'confirmed'],
            'roles'         => ['required', 'array'],
            'approved'      => ['nullable', 'integer'],
            'status'        => ['nullable', 'integer']
        ]);
        if ($validator->fails())
        {
            session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.users.create');
        }
        $user = User::create([
            'fname'                 => $data['fname'],
            'lname'                 => $data['lname'],
            'email'                 => $data['email'],
            'password'              => Hash::make($data['password']),
            'home_phone'            => '',
            'cell_phone'            => '',
            'address'               => '',
            'city'                  => '',
            'state_id'              => 1,
            'pcode'                 => '',
            'country_id'            => 1,
            'grade_id'              => 1,
            'parent_fname'          => '',
            'parent_lname'          => '',
            'school'                => '',
            'referrer_id'           => 1,
            'service_method'        => ''
        ]);
        if ($user == NULL)
        {
            session()->flash('error', "There is an error creating the user!");
            return redirect()->route('admin.users.create');
        }
        foreach ($data['roles'] as $role) {
            $user->roles()->attach($role);
        }
        $user->save();
        session()->flash('success', $user->fname . $user->lname . " has been created successfully");
        return redirect()->route('admin.users.index');
    }
public function store ( Request $ request ) { if ( Gate :: denies ( 'manage-users' ) ) return redirect ( ) -> route ( 'admin.users.create' ) ; $ data = $ request -> all ( ) ; $ validator = Validator :: make ( $ data , [ 'fname' => [ 'required' , 'string' , 'max:255' ] , 'lname' => [ 'required' , 'string' , 'max:255' ] , 'email' => [ 'required' , 'string' , 'email' , 'max:255' , 'unique:users' ] , 'password' => [ 'required' , 'string' , 'min:8' , 'confirmed' ] , 'roles' => [ 'required' , 'array' ] , 'approved' => [ 'nullable' , 'integer' ] , 'status' => [ 'nullable' , 'integer' ] ] ) ; if ( $ validator -> fails ( ) ) { session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.users.create' ) ; } $ user = User :: create ( [ 'fname' => $ data [ 'fname' ] , 'lname' => $ data [ 'lname' ] , 'email' => $ data [ 'email' ] , 'password' => Hash :: make ( $ data [ 'password' ] ) , 'home_phone' => '' , 'cell_phone' => '' , 'address' => '' , 'city' => '' , 'state_id' => 1 , 'pcode' => '' , 'country_id' => 1 , 'grade_id' => 1 , 'parent_fname' => '' , 'parent_lname' => '' , 'school' => '' , 'referrer_id' => 1 , 'service_method' => '' ] ) ; if ( $ user == NULL ) { session ( ) -> flash ( 'error' , " There is an error creating the user! " ) ; return redirect ( ) -> route ( 'admin.users.create' ) ; } foreach ( $ data [ 'roles' ] as $ role ) { $ user -> roles ( ) -> attach ( $ role ) ; } $ user -> save ( ) ; session ( ) -> flash ( 'success' , $ user -> fname . $ user -> lname . "  has been created successfully " ) ; return redirect ( ) -> route ( 'admin.users.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .