master

laravel/framework

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

MultipleRecordsFoundException.php

TLDR

This file defines the MultipleRecordsFoundException class, which is an exception class that extends the RuntimeException class. It represents an exception that occurs when multiple records are found in the database.

Classes

MultipleRecordsFoundException

The MultipleRecordsFoundException class represents an exception that is thrown when multiple records are found in the database. It extends the RuntimeException class.

Properties

  • $count - The number of records found.

Methods

  • __construct($count, $code = 0, $previous = null) - Creates a new instance of the exception. It takes the count of records found, an optional code, and an optional previous exception as parameters.
  • getCount() - Gets the number of records found.
<?php

namespace Illuminate\Database;

use RuntimeException;

class MultipleRecordsFoundException extends RuntimeException
{
    /**
     * The number of records found.
     *
     * @var int
     */
    public $count;

    /**
     * Create a new exception instance.
     *
     * @param  int  $count
     * @param  int  $code
     * @param  \Throwable|null  $previous
     * @return void
     */
    public function __construct($count, $code = 0, $previous = null)
    {
        $this->count = $count;

        parent::__construct("$count records were found.", $code, $previous);
    }

    /**
     * Get the number of records found.
     *
     * @return int
     */
    public function getCount()
    {
        return $this->count;
    }
}