// Increment votes by 1 DB::table('users')->increment('votes');
// Increment votes by 5 DB::table('users')->increment('votes', 5);
// Decrement votes by 1 DB::table('users')->decrement('votes');
// Decrement votes by 5 DB::table('users')->decrement('votes', 5);
// Increment votes by 1 and set the name to John DB::table('users')->increment('votes', 1, ['name' => 'John']);
// You can increment multiple columns at once DB::table('users')->incrementEach([ 'votes' => 5, // Will increment votes by 5 'balance' => 100, // Will increment balance by 100 ]);
// You can also use them with Eloquent User::query()->incrementEach([ 'votes' => 5, // Will increment votes by 5 'balance' => 100 // Will increment balance by 100 ]);
@foreach ($users as $user) @foreach ($user->posts as $post) @if ($loop->parent->first) // This is the first iteration of the parent loop. @endif @endforeach @endforeach
$result1 = collect([1, 2, 3])->every(function (int $value, int $key) { return$value > 2;} ); // $result will be false
$result2 = collect([])->every(function (int $value, int $key){ return$value > 2;}); // Since the collectionis empty, $result will be true dump($result1,$result2);
// We've all done this, the regular implode() collect(['a', 'b', 'c'])->join(', ', ''); // 'a, b, c'
// But did you know you can specify the last separator? collect(['a', 'b', 'c'])->join(', ', ', and '); // 'a, b, and c'
// And it's smart enough to handle edge cases collect(['a'])->join(', ', ', and '); // 'a' collect([])->join(', ', ', and '); // ''
在“find”中使用多个 ID 和特定列
我们经常使用“find()”,但你知道你可以传递 ID 数组并选择特定的列吗?🚀
1 2 3 4
<?php // You can pass an array of ids, an select specific columns User::find([1, 2], ['email']); // select `email` from `users` where `users`.`id` in (1, 2)
在命令中请求确认
您是否知道,您可以在执行有风险的命令之前请求确认?您可以使用“确认”方法执行此操作🚀
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php
// Displays the old Laravel prompt view $this->confirm('Do you want to continue?');
// With "components", it displays the modern Laravel prompt view $this->components->confirm('Do you want to continue?');
// In your terminal, you should see /* * Do you want to continue? (yes/no) [no] * */
// Increment votes by 1 DB::table('users')->increment('votes');
// Increment votes by 5 DB::table('users')->increment('votes', 5);
// Decrement votes by 1 DB::table('users')->decrement('votes');
// Decrement votes by 5 DB::table('users')->decrement('votes', 5);
// Increment votes by 1 and set the name to John DB::table('users')->increment('votes', 1, ['name' => 'John']);
// You can increment multiple columns at once DB::table('users')->incrementEach([ 'votes' => 5, // Will increment votes by 5 'balance' => 100, // Will increment balance by 100 ]);
// You can also use them with Eloquent User::query()->incrementEach([ 'votes' => 5, // Will increment votes by 5 'balance' => 100 // Will increment balance by 100 ]);
@foreach ($users as $user) @foreach ($user->posts as $post) @if ($loop->parent->first) // This is the first iteration of the parent loop. @endif @endforeach @endforeach
$result1 = collect([1, 2, 3])->every(function (int $value, int $key) { return$value > 2;} ); // $result will be false
$result2 = collect([])->every(function (int $value, int $key){ return$value > 2;}); // Since the collectionis empty, $result will be true dump($result1,$result2);
// We've all done this, the regular implode() collect(['a', 'b', 'c'])->join(', ', ''); // 'a, b, c'
// But did you know you can specify the last separator? collect(['a', 'b', 'c'])->join(', ', ', and '); // 'a, b, and c'
// And it's smart enough to handle edge cases collect(['a'])->join(', ', ', and '); // 'a' collect([])->join(', ', ', and '); // ''
在“find”中使用多个 ID 和特定列
我们经常使用“find()”,但你知道你可以传递 ID 数组并选择特定的列吗?🚀
1 2 3 4
<?php // You can pass an array of ids, an select specific columns User::find([1, 2], ['email']); // select `email` from `users` where `users`.`id` in (1, 2)
在命令中请求确认
您是否知道,您可以在执行有风险的命令之前请求确认?您可以使用“确认”方法执行此操作🚀
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php
// Displays the old Laravel prompt view $this->confirm('Do you want to continue?');
// With "components", it displays the modern Laravel prompt view $this->components->confirm('Do you want to continue?');
// In your terminal, you should see /* * Do you want to continue? (yes/no) [no] * */
// Increment votes by 1 DB::table('users')->increment('votes');
// Increment votes by 5 DB::table('users')->increment('votes', 5);
// Decrement votes by 1 DB::table('users')->decrement('votes');
// Decrement votes by 5 DB::table('users')->decrement('votes', 5);
// Increment votes by 1 and set the name to John DB::table('users')->increment('votes', 1, ['name' => 'John']);
// You can increment multiple columns at once DB::table('users')->incrementEach([ 'votes' => 5, // Will increment votes by 5 'balance' => 100, // Will increment balance by 100 ]);
// You can also use them with Eloquent User::query()->incrementEach([ 'votes' => 5, // Will increment votes by 5 'balance' => 100 // Will increment balance by 100 ]);
@foreach ($users as $user) @foreach ($user->posts as $post) @if ($loop->parent->first) // This is the first iteration of the parent loop. @endif @endforeach @endforeach
$result1 = collect([1, 2, 3])->every(function (int $value, int $key) { return$value > 2;} ); // $result will be false
$result2 = collect([])->every(function (int $value, int $key){ return$value > 2;}); // Since the collectionis empty, $result will be true dump($result1,$result2);
// We've all done this, the regular implode() collect(['a', 'b', 'c'])->join(', ', ''); // 'a, b, c'
// But did you know you can specify the last separator? collect(['a', 'b', 'c'])->join(', ', ', and '); // 'a, b, and c'
// And it's smart enough to handle edge cases collect(['a'])->join(', ', ', and '); // 'a' collect([])->join(', ', ', and '); // ''
在“find”中使用多个 ID 和特定列
我们经常使用“find()”,但你知道你可以传递 ID 数组并选择特定的列吗?🚀
1 2 3 4
<?php // You can pass an array of ids, an select specific columns User::find([1, 2], ['email']); // select `email` from `users` where `users`.`id` in (1, 2)
在命令中请求确认
您是否知道,您可以在执行有风险的命令之前请求确认?您可以使用“确认”方法执行此操作🚀
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php
// Displays the old Laravel prompt view $this->confirm('Do you want to continue?');
// With "components", it displays the modern Laravel prompt view $this->components->confirm('Do you want to continue?');
// In your terminal, you should see /* * Do you want to continue? (yes/no) [no] * */