@@ -492,4 +492,67 @@ public function __call($method, $parameters)
492492
493493 return parent ::__call ($ method , $ parameters );
494494 }
495+
496+ /**
497+ * @inheritdoc
498+ */
499+ public function newCollection (array $ models = []): \Illuminate \Database \Eloquent \Collection
500+ {
501+ return \function_exists ('arrayUniqueSortRegular ' )
502+ && \Composer \InstalledVersions::isInstalled ('macropay-solutions/maravel-framework ' ) ?
503+ parent ::newCollection ($ models ) :
504+ new class ($ models ) extends \Illuminate \Database \Eloquent \Collection {
505+ /**
506+ * @inheritdoc
507+ */
508+ public function toBase (): Collection
509+ {
510+ return new class ($ this ) extends Collection {
511+ /**
512+ * Return only unique items from the collection array.
513+ *
514+ * @param mixed $key
515+ * @param bool $strict
516+ * @param int $flags [optional] <p>
517+ * The optional second parameter sort_flags
518+ * may be used to modify the sorting behavior using these values:
519+ * </p>
520+ * <p>
521+ * Sorting type flags:
522+ * </p><ul>
523+ * <li>
524+ * <b>SORT_REGULAR</b> - compare items normally
525+ * (don't change types)
526+ * </li>
527+ * <li>
528+ * <b>SORT_NUMERIC</b> - compare items numerically
529+ * </li>
530+ * <li>
531+ * <b>SORT_STRING</b> - compare items as strings
532+ * </li>
533+ * <li>
534+ * <b>SORT_LOCALE_STRING</b> - compare items as strings,
535+ * based on the current locale
536+ * </li>
537+ * </ul>
538+ * @return static
539+ */
540+ public function unique ($ key = null , $ strict = false ): Collection
541+ {
542+ if ($ key === null && $ strict === false ) {
543+ $ flags = \func_get_args ()[2 ] ?? SORT_REGULAR ;
544+
545+ return new static (
546+ SORT_REGULAR === $ flags ?
547+ GeneralHelper::arrayUniqueSortRegular ($ this ->items ) :
548+ \array_unique ($ this ->items , $ flags )
549+ );
550+ }
551+
552+ return parent ::unique ($ key , $ strict );
553+ }
554+ };
555+ }
556+ };
557+ }
495558}
0 commit comments