Laravel 让这很容易,在你的情况下你会使用
$maxValue = Cliente::max('id');
但您也可以从表中检索最新记录,这也是最高值
$newestCliente = Cliente::orderBy('id', 'desc')->first(); // gets the whole row
$maxValue = $newestCliente->id;
或者只是为了价值
$maxValue = Cliente::orderBy('id', 'desc')->value('id'); // gets only the id
或者,如果您有一个带有日期的 created_at
列,您可以获得这样的值
$maxValue = Cliente::latest()->value('id');
相关 Laravel 文档:https://laravel.com/docs/5.5/queries#aggregates
$maxValue = DB::table('Clientes')->max('id');
Cliente::where('column_name', $your_Valu)->max('id') // You get any max column
我们可以使用以下代码:
$min_id = DB::table('table_name')->max('id');
https://laravel.com/docs/8.x/queries#aggregates
不定期副业成功案例分享
where
条件