master

laravel/framework

Last updated at: 29/12/2023 09:24

MergeValue.php

TLDR

This file defines a class called MergeValue in the Illuminate\Http\Resources namespace. The class contains a constructor that takes in a parameter and assigns it to the data property of the class.

Classes

MergeValue

This class represents a merge value. It has a constructor that accepts a parameter data, which can be either an instance of Illuminate\Support\Collection, an instance of JsonSerializable, or an array. The constructor assigns the value of data to the data property of the class.

<?php

namespace Illuminate\Http\Resources;

use Illuminate\Support\Collection;
use JsonSerializable;

class MergeValue
{
    /**
     * The data to be merged.
     *
     * @var array
     */
    public $data;

    /**
     * Create a new merge value instance.
     *
     * @param  \Illuminate\Support\Collection|\JsonSerializable|array  $data
     * @return void
     */
    public function __construct($data)
    {
        if ($data instanceof Collection) {
            $this->data = $data->all();
        } elseif ($data instanceof JsonSerializable) {
            $this->data = $data->jsonSerialize();
        } else {
            $this->data = $data;
        }
    }
}