Log.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 $fillable = [
  12. 'description','type','method', 'class', 'ip','id_user','created_at','updated_at'
  13. ];
  14. function user(): HasOne
  15. {
  16. return $this->hasOne(User::class, 'id','id_user');
  17. }
  18. public function getExceptionMarkAttribute(){
  19. if (Str::upper(substr($this->method,0,1)) != 'E')return 'N';
  20. if (Str::upper(substr($this->method,0,5)) == 'ERROR' || Str::upper(substr($this->method,0,9)) == 'EXCEPTION')
  21. return 'Y';
  22. return 'N';
  23. }
  24. // public function getDescriptionAttribute($value): string
  25. // {
  26. // return str_replace(
  27. // ["\n","\r\n"],
  28. // ' ',
  29. // $value);
  30. // }
  31. public function scopeFilter($query, $filters)
  32. {
  33. return $filters->apply($query);
  34. }
  35. }