master

laravel/framework

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

MissingAttributeException.php

TLDR

This file defines the MissingAttributeException class, which extends the OutOfBoundsException class. It is used to throw an exception when a requested attribute either does not exist or was not retrieved for a model.

Classes

MissingAttributeException

The MissingAttributeException class extends the OutOfBoundsException class. It is used to throw an exception when a requested attribute either does not exist or was not retrieved for a model. The class has a constructor method that takes in a model and a key, and it formats and throws an exception message that indicates the missing attribute and the model class. This class does not have any additional methods.

<?php

namespace Illuminate\Database\Eloquent;

use OutOfBoundsException;

class MissingAttributeException extends OutOfBoundsException
{
    /**
     * Create a new missing attribute exception instance.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @param  string  $key
     * @return void
     */
    public function __construct($model, $key)
    {
        parent::__construct(sprintf(
            'The attribute [%s] either does not exist or was not retrieved for model [%s].',
            $key, get_class($model)
        ));
    }
}