| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Observers;
- use App\Authority;
- class AuthorityObserver
- {
- /**
- * Handle the authority "created" event.
- *
- * @param \App\Authority $authority
- * @return void
- */
- public function created(Authority $authority)
- {
- if (env('APP_ENV')!='production')return;
- $txt = "INSERT INTO authorities";
- $columns = "(";
- $values = "(";
- foreach ($authority->toArray() as $col=>$val){
- $columns .= "{$col},";
- $values .= "'{$val}',";
- }
- $columns = mb_substr($columns,0,-1);
- $values = mb_substr($values,0,-1);
- $txt .= "{$columns}) VALUES{$values});\r\n";
- $this->write($txt);
- }
- /**
- * Handle the authority "updated" event.
- *
- * @param \App\Authority $authority
- * @return void
- */
- public function updated(Authority $authority)
- {
- if (env('APP_ENV')!='production')return;
- $txt = "UPDATE authorities SET ";
- foreach ($authority->toArray() as $col=>$val)$txt .= "{$col}='{$val}',";
- $txt = mb_substr($txt,0,-1);
- $txt .= " WHERE id = {$authority->id};\r\n";
- $this->write($txt);
- }
- /**
- * Handle the authority "deleted" event.
- *
- * @param \App\Authority $authority
- * @return void
- */
- public function deleted(Authority $authority)
- {
- if (env('APP_ENV')!='production')return;
- $txt = "DELETE FROM authorities WHERE id = {$authority->id};\r\n";
- $this->write($txt);
- }
- private function write($txt)
- {
- $myfile = fopen(base_path()."\\database\\data\\authorities.data", "a+");
- fwrite($myfile, $txt);
- fclose($myfile);
- }
- }
|