master

laravel/framework

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

SerializesCastableAttributes.php

TLDR

This file is an interface that belongs to the Illuminate\Contracts\Database\Eloquent namespace. It includes a single method called serialize that is used to serialize an attribute when converting a model to an array.

Methods

serialize

This method is responsible for serializing an attribute when converting a model to an array. It takes four parameters:

  • $model: An instance of the \Illuminate\Database\Eloquent\Model class representing the model being serialized.
  • $key: A string representing the key of the attribute being serialized.
  • $value: The value of the attribute being serialized. It can be of any type.
  • $attributes: An array representing the model's attributes.

The method should return the serialized value of the attribute.

Classes

<?php

namespace Illuminate\Contracts\Database\Eloquent;

use Illuminate\Database\Eloquent\Model;

interface SerializesCastableAttributes
{
    /**
     * Serialize the attribute when converting the model to an array.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @param  string  $key
     * @param  mixed  $value
     * @param  array  $attributes
     * @return mixed
     */
    public function serialize(Model $model, string $key, mixed $value, array $attributes);
}