master

laravel/framework

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

Exists.php

TLDR

The file Exists.php is a part of the Illuminate\Validation\Rules namespace and defines the Exists class. This class implements the Stringable interface and uses the Conditionable and DatabaseRule traits. The class defines a __toString method to convert the rule to a validation string.

Classes

Exists

The Exists class is a validation rule that checks if a given value exists in a specified database table and column. It implements the Stringable interface and uses the Conditionable and DatabaseRule traits.

Class Exists

The Exists class has the following methods:

__toString()

This method converts the rule to a validation string. It returns a string in the format exists:table,column,whereClauses. The whereClauses represent the additional conditions to be applied when checking for existance.

<?php

namespace Illuminate\Validation\Rules;

use Illuminate\Support\Traits\Conditionable;
use Stringable;

class Exists implements Stringable
{
    use Conditionable, DatabaseRule;

    /**
     * Convert the rule to a validation string.
     *
     * @return string
     */
    public function __toString()
    {
        return rtrim(sprintf('exists:%s,%s,%s',
            $this->table,
            $this->column,
            $this->formatWheres()
        ), ',');
    }
}