2016-05-03 43 views

回答

4

您需要爲模型添加驗證邏輯。凡關係稱爲somerelation,在模型類中定義這樣的方法:

public function beforeValidate() 
{ 
    $file = $this->somerelation()->withDeferred($this->sessionKey)->first(); 
    $filename = $file->getLocalPath(); 
    list($width, $height) = getimagesize($filename); 

    if ($width < 800) { 
     throw new ValidationException(['somerelation' => 'Width must be greater than 800']); 
    } 
} 

對於這種方法覆蓋工作,確保模型已經使用了October\Rain\Database\Traits\Validation特質。因爲它只發生在後端,所以快速檢查App::runningInBackend()應該可以做到。

0

使用它它會給圖像的寬度和高度。

list($width, $height) = getimagesize($filename);