#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2018
    Location
    2408 Oakmound Road,Chicago, IL, 60641
    Posts
    9
    Rep Power
    0

    Auto-increment functionality


    I have been struggling to find out a way to reset the auto increment value in Laravel 4 but it seems that this functionality is not embedded in laravel 4 at least for now. so I did it this way:

    PHP Code:
    $user User::find($user_id);

                    if (
    $user)  {
                        if (
    $user->delete()){

                        
    DB::statement('ALTER TABLE users AUTO_INCREMENT = '.(count(User::all())+1).';');

                        echo 
    json_encode('User Was Deleted Successfully..');
                        }   
                } 
    each time I delete a user from the database I set the auto increment pointer to the number of all users +1.

    if anybody has a better solution inform me, please...
  2. #2
  3. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,739
    Rep Power
    9646
    Don't do that. It's perfectly fine to have "holes". Leave it alone.

IMN logo majestic logo threadwatch logo seochat tools logo