master

laravel/framework

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

MultipleItemsFoundException.php

TLDR

This file defines the MultipleItemsFoundException class, which extends the RuntimeException class. It is used to represent an exception when multiple items are found, and it provides methods to get the count of items found.

Classes

MultipleItemsFoundException

This class extends the RuntimeException class and is used to represent an exception when multiple items are found. It has the following methods:

  • __construct($count, $code = 0, $previous = null): Constructs a new exception instance with the number of items found as the $count parameter.
  • getCount(): Returns the number of items found.
<?php

namespace Illuminate\Support;

use RuntimeException;

class MultipleItemsFoundException extends RuntimeException
{
    /**
     * The number of items 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 items were found.", $code, $previous);
    }

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