“Koleksi Laravel Unik” Kode Jawaban

Koleksi Laravel Unik

$collection = collect([
    ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],
    ['name' => 'iPhone 5', 'brand' => 'Apple', 'type' => 'phone'],
    ['name' => 'Apple Watch', 'brand' => 'Apple', 'type' => 'watch'],
    ['name' => 'Galaxy S6', 'brand' => 'Samsung', 'type' => 'phone'],
    ['name' => 'Galaxy Gear', 'brand' => 'Samsung', 'type' => 'watch'],
]);
 
$unique = $collection->unique('brand');
 
$unique->values()->all();
 
/*
    [
        ['name' => 'iPhone 6', 'brand' => 'Apple', 'type' => 'phone'],
        ['name' => 'Galaxy S6', 'brand' => 'Samsung', 'type' => 'phone'],
    ]
*/
Shadow

koleksi filter laravel

$collection = collect([1, 2, 3, 4]);

$filtered = $collection->filter(function ($value, $key) {
    return $value > 2;
});

$filtered->all();

// [3, 4]
Relieved Raccoon

Koleksi Laravel Unik

$collection = collect([1, 1, 2, 2, 3, 4, 2]);

$unique = $collection->unique();

$unique->values()->all();

// [1, 2, 3, 4]
Cooperative Crab

Tambahkan ke koleksi Laravel

$item = collect();
$item->push($product);
Grotesque Gibbon

Laravel Validasi Unik

/**
 * Store a new blog post.
 *
 * @param  Request  $request
 * @return Response
 */

public function store(Request $request)
{
    $validatedData = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ]);

    // The blog post is valid...
}
Handsome Hawk

Koleksi Laravel Unik

$users = $users->unique();
Cooperative Crab

Jawaban yang mirip dengan “Koleksi Laravel Unik”

Pertanyaan yang mirip dengan “Koleksi Laravel Unik”

Lebih banyak jawaban terkait untuk “Koleksi Laravel Unik” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya