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

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 :: how to print any string in double quotes in php 
Php :: Target class [AppHttpControllersAdminUserController] does not exist. larvel 8 
Php :: php date format dd-mm-yyyy 
Php :: php sql insert into if not exists 
Php :: store a variable in session and echo that variable on a page wordpress 
Php :: remove exact characters from string using php 
Php :: Email "" does not comply with addr-spec of RFC 2822. 
Php :: can you call a javascript cookie using php 
Php :: learn php 
Php :: crrate model in laravel 
Php :: dateinterval hh mm ss 
Php :: tackel discount in javascript 
Java :: spigot execute command as console 
Java :: camera permission android 
Java :: spring jpa repository gradle 
Java :: java print stack trace to string 
Java :: javafx button color 
Java :: spring application properties mysql jpa 
Java :: The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 
Java :: how to write on top of equal sign in latex 
Java :: how to get the width and height of a string in java 
Java :: how to install java 8 on aws linux 
Java :: array to map java4 
Java :: java bufferedimage get raster data 
Java :: guess the number java 
Java :: how to vibrate android java 
Java :: android back navigation 
Java :: javax.xml.bind does not exist 
Java :: how to remove character from stringbuilder in java 
Java :: long to int java 8 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =