app/Http/Controllers/UsersManagementController.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)
    {
        $create_new_validator = $this->create_new_validator($request->all());
        if ($create_new_validator->fails()) {
            $this->throwValidationException(
                $request, $create_new_validator
                );
        }
        else
        {
            $activation_code        = str_random(60) . $request->input('email');
            $user                   = new User;
            $user->email            = $request->input('email');
            $user->name             = $request->input('name');
            $user->empresa          = $request->input('empresa');
            $user->first_name       = $request->input('first_name');
            $user->last_name        = $request->input('last_name');
            $userAccessLevel        = $request->input('user_level');
            $user->password         = bcrypt($request->input('password'));
            $user->activation_code  = $activation_code;
            $user->active           = '1';
            $userIpAddress          = new CaptureIp;
            $user->admin_ip_address = $userIpAddress->getClientIp();
            $user->save();
            $role = Role::find($userAccessLevel);
            $role->users()->save($user);
            $pic = NULL;
            if(Input::file('user_profile_pic') != NULL){
                $user_profile_pic    = Input::file('user_profile_pic');
                $filename           = 'user-pic.' . $user_profile_pic->getClientOriginalExtension();
                $save_path          = storage_path() . '/users/id/' . $user->id . '/uploads/images/profile-pics/';
                File::makeDirectory($save_path, $mode = 0755, true, true);
                Image::make($user_profile_pic)->save($save_path . $filename);
                $pic = '/images/profile/' . $user->id . '/pics/' . $filename;
            }
            $profile = new Profile;
            $profile->bio = $request->input('bio');
            $profile->phone = $request->input('phone');
            $profile->skype_user = $request->input('skype_user');
            $profile->profile_pic = $pic;
            $user->profile()->save($profile);
            return redirect('users')->with('status', 'Usuario creado éxitosamente!');
        }
    }
public function store ( Request $ request ) { $ create_new_validator = $ this -> create_new_validator ( $ request -> all ( ) ) ; if ( $ create_new_validator -> fails ( ) ) { $ this -> throwValidationException ( $ request , $ create_new_validator ) ; } else { $ activation_code = str_random ( 60 ) . $ request -> input ( 'email' ) ; $ user = new User ; $ user -> email = $ request -> input ( 'email' ) ; $ user -> name = $ request -> input ( 'name' ) ; $ user -> empresa = $ request -> input ( 'empresa' ) ; $ user -> first_name = $ request -> input ( 'first_name' ) ; $ user -> last_name = $ request -> input ( 'last_name' ) ; $ userAccessLevel = $ request -> input ( 'user_level' ) ; $ user -> password = bcrypt ( $ request -> input ( 'password' ) ) ; $ user -> activation_code = $ activation_code ; $ user -> active = '1' ; $ userIpAddress = new CaptureIp ; $ user -> admin_ip_address = $ userIpAddress -> getClientIp ( ) ; $ user -> save ( ) ; $ role = Role :: find ( $ userAccessLevel ) ; $ role -> users ( ) -> save ( $ user ) ; $ pic = NULL ; if ( Input :: file ( 'user_profile_pic' ) != NULL ) { $ user_profile_pic = Input :: file ( 'user_profile_pic' ) ; $ filename = 'user-pic.' . $ user_profile_pic -> getClientOriginalExtension ( ) ; $ save_path = storage_path ( ) . '/users/id/' . $ user -> id . '/uploads/images/profile-pics/' ; File :: makeDirectory ( $ save_path , $ mode = 0755 , true , true ) ; Image :: make ( $ user_profile_pic ) -> save ( $ save_path . $ filename ) ; $ pic = '/images/profile/' . $ user -> id . '/pics/' . $ filename ; } $ profile = new Profile ; $ profile -> bio = $ request -> input ( 'bio' ) ; $ profile -> phone = $ request -> input ( 'phone' ) ; $ profile -> skype_user = $ request -> input ( 'skype_user' ) ; $ profile -> profile_pic = $ pic ; $ user -> profile ( ) -> save ( $ profile ) ; return redirect ( 'users' ) -> with ( 'status' , 'Usuario creado éxitosamente!') ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// GET ACTIVATION CODE // GET IP ADDRESS // SAVE THE USER // CHECK FOR USER PROFILE IMAGE FILE UPLOAD // MAKE USER FOLDER AND UPDATE PERMISSIONS // SAVE FILE TO SERVER // SAVE ROUTED PATH TO IMAGE TO DATABASE // CREATE PROFILE LINK TO TABLE // THE SUCCESSFUL RETURN