minuteoflaravel/laravel-audio-video-validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

minuteoflaravel/laravel-audio-video-validator

最新稳定版本:1.1

Composer 安装命令:

composer require minuteoflaravel/laravel-audio-video-validator

包简介

Laravel validator for video and audio files

README 文档

README

This package adds validators for audio and video files to your Laravel project.

Installation

To use this package you should intall ffmpeg multimedia framework:

  • On Debian/Ubuntu, run sudo apt install ffmpeg
  • On macOS with Homebrew: brew install ffmpeg

After that install the package via composer:

composer require minuteoflaravel/laravel-audio-video-validator

Validators

Package adds these validators:

  • audio
  • video
  • codec
  • duration
  • duration_max
  • duration_min
  • video_width
  • video_height
  • video_max_width
  • video_max_height
  • video_min_width
  • video_min_height

Custom error messages

If you need to add your custom translatable error messages then just add them as always to resources/lang/en/validation.php file:

  'audio' => 'The :attribute must be a audio.',
  'video' => 'The :attribute must be a video.',
  'codec' => 'The :attribute codec must be one of these: :codec',
  'duration' => 'The :attribute must be :duration seconds duration.',
  'duration_max' => 'The :attribute duration must be less than :duration_max seconds.',
  'duration_min' => 'The :attribute duration must be greater than :duration_min seconds.',
  'video_width' => 'The :attribute width must be :video_width.',
  'video_height' => 'The :attribute height must be :video_height.',
  'video_max_width' => 'The :attribute width must be less than :video_max_width.',
  'video_min_width' => 'The :attribute width must be greater than :video_min_width.',
  'video_min_height' => 'The :attribute height must be greater than :video_min_height.',

Some examples

To check if file is audio file and audio duration is 60 seconds:

$request->validate([
    'audio' => 'audio|duration:60',
]);

To check if file is audio file and audio duration is between 30 and 300 seconds:

$request->validate([
    'audio' => 'audio|duration_min:30|duration_max:300',
]);

To check if file is video file and video duration is between 30 and 300 seconds:

$request->validate([
    'video' => 'video|duration_min:30|duration_max:300',
]);

To check if file is video file and video dimensions are 1000x640:

$request->validate([
    'video' => 'video|video_width:1000|video_height:640',
]);

To check if file is video file and video dimensions greater than 1000x640:

$request->validate([
    'video' => 'video|video_min_width:1000|video_min_height:640',
]);

To check if file is audio file and codec is mp3 or pcm_s16le(wav):

$request->validate([
    'audio' => 'audio|codec:mp3,pcm_s16le',
]);

To check if file is video file and codec is h264(mp4):

$request->validate([
    'video' => 'video|codec:h264',
]);

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 55.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 97
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 97
  • Watchers: 3
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-02