square / laravel-hyrule

Object-oriented, composable, fluent API for writing validations in Laravel
Apache License 2.0
340 stars 10 forks source link

[Feature] Implement `FileNode` #8

Closed bezhermoso closed 2 years ago

bezhermoso commented 2 years ago

Addresses https://github.com/square/laravel-hyrule/issues/7

Example 1: Images

$builder = Hyrule::create()
    ->file('avatar')
       ->image()
       ->dimensions()
           ->ratio(1)
           ->maxWidth(1000)
           ->end()
       ->end()
    ->string('username')
       // etc.

Example 2: Other MIME types

$builder = Hyrule::create()
    ->file('scan')
       ->mimeType()
           ->allow('application/pdf')
           ->image('jpg', 'png') // allows image/jpg & image/png
       ->end()
    ->string('username')
       // etc.

Example 3: Array of files

$builder = Hyrule::create()
    ->array('attachments')
       ->between(1, 10)
       ->each('file')
          ->mimeType()
            ->allow('application/pdf')
            ->image('jpg', 'png') // allows image/jpg & image/png
            ->text('plain', 'html') // allows text/plain & text/html
            ->video('mp4') // allows video/mp4
            ->end()
        ->end()
      ->end()
    ->string('username')
       // etc.