Log.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\ModelTimeFormat;
  5. use Illuminate\Database\Eloquent\Relations\HasOne;
  6. use Illuminate\Support\Str;
  7. use App\Traits\ModelLogChanging;
  8. class Log extends Model
  9. {
  10. use ModelTimeFormat;
  11. protected $connection="mysql3306";
  12. protected $fillable = [
  13. 'description','type','method', 'class', 'ip','id_user','created_at','updated_at'
  14. ];
  15. function user(): HasOne
  16. {
  17. return $this->hasOne(User::class, 'id','id_user');
  18. }
  19. public function getExceptionMarkAttribute(){
  20. if (Str::upper(substr($this->method,0,1)) != 'E')return 'N';
  21. if (Str::upper(substr($this->method,0,5)) == 'ERROR' || Str::upper(substr($this->method,0,9)) == 'EXCEPTION')
  22. return 'Y';
  23. return 'N';
  24. }
  25. // public function getDescriptionAttribute($value): string
  26. // {
  27. // return str_replace(
  28. // ["\n","\r\n"],
  29. // ' ',
  30. // $value);
  31. // }
  32. public function scopeFilter($query, $filters)
  33. {
  34. return $filters->apply($query);
  35. }
  36. }