Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel collection unique

$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'],
    ]
*/
Comment

get unique values in laravel

$users = User::select('name')->distinct()->get();
Comment

laravel collection unique

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

$unique = $collection->unique();

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

// [1, 2, 3, 4]
Comment

Laravel Collection Get Unique Values

<?php
  
namespace AppHttpControllers;
  
class ITSController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $data = [1,2,4,5,3,2,2,4,5,6,8,9];
  
        $data  = collect($data)->unique();
  
        dd($data);
    }
}
Comment

laravel collection unique

$users = $users->unique();
Comment

PREVIOUS NEXT
Code Example
Php :: POP UP WITH PHP 
Php :: php get screen size 
Php :: how make a variable global php 
Php :: update image in database using php 
Php :: Custom Font Laravel 
Php :: max title limit woocommerce product 
Php :: create email template php 
Php :: header php location 
Php :: laravel Please provide a valid cache path 
Php :: php post variables to another page with submit button php 
Php :: select option edit in laravel 
Php :: qr code generator php 
Php :: php super 
Php :: php insert array into mysql 
Php :: Sum two numbers in PHP with HTML input form 
Php :: laravel update email unique 
Php :: add two numbers in php 
Php :: php exec get pid 
Php :: how to make a loop that adds numbers to a variable in php 
Php :: all resource routes laravel 8 
Php :: php validate colour 
Php :: How to create a route in laravel? 
Php :: wordpress widget current year 
Php :: laravel intersect 
Php :: get file request in laravel 
Php :: php try json decode and check 
Php :: send mail using php mail function on localhost using xampp server 
Php :: livewire call function from other component 
Php :: how to print on console with phpunit 
Php :: php object to string 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =