1
아래 코드에서 볼 수있는 것처럼 모델의 두 이벤트를 업데이트하고 업데이트했습니다. 내 관심사는 teacherId가 변경된 경우에만 업데이트 된 이벤트에서 일부 작업을 수행하기를 원하므로 업데이트 이벤트에서 값을 확인하고 클래스 속성을 사용하여 변경되었거나 아닌지 알았지 만 그 플래그 정의 된 값을 가정 할 때 항상 false를 반환합니다.laravel 관측기의 메소드 간 변수
namespace App\Observers;
class SubjectObserver {
private $shouldUpdateThreads = false;
/**
* Listen to the ThreadList created event.
* This events Fire when ThreadList is handled
* @param \App\Observers\App\ThreadList $threadList
*/
public function created(\subject $subject) {
}
/**
* Listen to the ThreadList saved event.
* @param \App\Observers\App\ThreadList $threadList
*/
public function saved(\subject $subject) {
}
/**
* Handling subject updated event
* Used to update the threads and related models
* @param \subject $subject
*/
public function updated(\subject $subject) {
info('After Update Event ' . $this->shouldUpdateThreads);
if ($this->shouldUpdateThreads) {
info_plus($subject);
}
info('After Update Check');
}
/**
* Handling subject being updated event
* Used to check if the teachers data has changed or not
* @param \subject $subject
*/
public function updating(\subject $_subject) {
$subject = \subject::find($_subject->id);
$this->shouldUpdateThreads = ($subject->teacherId != $_subject->teacherId) ? true : false;
info(($subject->teacherId != $_subject->teacherId));
info("Thread update ? " . $this->shouldUpdateThreads);
}
public function deleted(\subject $subject) {
info("Subject deleted");
}
}
이 정보가 적절한가요? 내가 뭘 잘못하고 있는거야?
쿨 나를 그렇게 해보자을 :) – BlackBurn027
저에게는 완벽하게 괜찮습니다. 감사합니다. – BlackBurn027