- Düzenlendi
kendi kullandığım base model örneği;
Her model de "rules" tanımlaması mecburidir;
Her model de "rules" tanımlaması mecburidir;
<?php
use Illuminate\Support\Facades\Validator;
class BaseModel extends Eloquent{
//protected $rules;
protected $errors;
public function validate($imodel){
//print_pre($imodel->getAttributes()); die();
$validator = Validator::make($imodel->getAttributes(), $imodel->rules);
if ($validator->fails()){
$this->errors = $validator->messages();
return false;
}
return true;
}
public static function boot() {
parent::boot();
static::saving(function($model){
return $model->validate($model);
});
}
public function errors()
{
return $this->errors;
}
}
daha etraflıca yazılmış bir örnek varsa yazım kolaylığı açısından güzel olurdu.