简体   繁体   中英

laravel : After delete record from database the new record is in the place of the deleted record

i have 10 records in my table when i delete record 5 and create new record the new record come in the place of the deleted record like this :

before delete record the ids its :
1 2 3 4 5 6 7 8 9 10

after delete record 5 and insert new record the id its 11 and the place it: 1 2 3 4 11 6 7 8 9 10

fetch data code :

$permissions = Permission::all();

delete code:

$permission = Permission::find($id)->delete();

create code:

Permission::create($request->all());

records in table :

records in database :

Without an orderBy , it's up to your database to decide the order. Database engines may handle this differently, so if it matters to you what order they're in, you need to tell the database that.

An explicit orderBy('id') (or another column, if it makes more sense for your app) in your database calls will ensure it's always in the order you expect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM