toArray() as $col=>$val){ $columns .= "{$col},"; if (!$val) $values .= "null,"; else $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 (config('app.env')!='production')return; $txt = "UPDATE authorities SET "; foreach ($authority->toArray() as $col=>$val){ if (!$val) $txt .= "{$col}=null,"; else $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 (config('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); } }