1
나는 웅변 모델의 create()
메소드를 덮어 쓰고 생성하기 전에 일부 필드를 변경 (암호화)하려고합니다.웅장한 create() 메소드 덮어 쓰기
public static create(array $data)
{
// for demonstrating purposes I just prepend a string
$data['fieldName'] = 'xxx'.$data['fieldName'];
// call the parent' create with the altered data-array
return parent::create($data)
}
그러나 어떻게 든이 오류가 발생합니다 : 나는 무엇을 놓치고
Declaration of App\MyModel::create() should be compatible with Illuminate\Database\Eloquent\Model::create(array $attributes = Array)
그래서 내 모델에서 내가있는 내가 필드를 변경, 새로운 방법을 선언?
public static function create(array $attributes = []) {
그러나 대신 당신은 또한 생성 이벤트를 수신하거나 설정하는 뮤 테이터를 사용할 수있는 방법을 덮어 쓰기 : 그것은 다음과 같이해야한다, 그래서
OMG laravel에는 이미 기본으로 구워지고 싶은 것이 있습니다 ... 뮤 테이터/액세서입니다. 고맙습니다. – stUrb