我想得到下一个id,它将被创建,但还没有在laravel中
我想得到下一个id,它将被创建,但还没有在laravel中。 这个代码正确吗我想得到下一个id,它将被创建,但还没有在laravel中,laravel,Laravel,我想得到下一个id,它将被创建,但还没有在laravel中。 这个代码正确吗 $tableStatus = DB::select("show table status from database_name where Name = 'table_name'"); if (empty($tableStatus)) { throw new \Exception("Table not found"); } // Get first table resul
$tableStatus = DB::select("show table status from database_name where Name = 'table_name'");
if (empty($tableStatus)) {
throw new \Exception("Table not found");
}
// Get first table result, get its next auto incrementing value
echo $tableStatus[0]->Auto_increment;
是的,代码是正确的。
您可以通过其他几种方式实现这一点。例如,您可以查询特定的数据库表以提取上次创建的id,方法是根据列或id列本身的创建值对行进行排序,最后将值递增1以获得下一个自动递增值