master

laravel/framework

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

ImageFile.php

TLDR

The ImageFile.php file is a class that extends the File class in the Illuminate\Validation\Rules namespace. It represents a rule for validating image files.

Classes

ImageFile

The ImageFile class is a rule class that extends the File class. It is used for validating image files. It has the following methods:

  • __construct(): Initializes a new instance of the ImageFile class. It sets the rule to 'image'.
  • dimensions($dimensions): Sets the dimension constraints for the uploaded file. Accepts an instance of the Illuminate\Validation\Rules\Dimensions class as a parameter. It adds the dimension rules to the existing rules.
<?php

namespace Illuminate\Validation\Rules;

class ImageFile extends File
{
    /**
     * Create a new image file rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->rules('image');
    }

    /**
     * The dimension constraints for the uploaded file.
     *
     * @param  \Illuminate\Validation\Rules\Dimensions  $dimensions
     */
    public function dimensions($dimensions)
    {
        $this->rules($dimensions);

        return $this;
    }
}