Guest User

Untitled

a guest
Nov 15th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Illuminate\Database\Eloquent\Model;
  6.  
  7. class Attachment extends Model
  8. {
  9. protected $guarded = [];
  10. protected $appends = ['url'];
  11. public function attachable()
  12. {
  13. return $this->morphTo();
  14. }
  15. public function getUrlAttribute()
  16. {
  17. return Storage::url($this->uid);
  18. }
  19. public static function boot()
  20. {
  21. parent::boot();
  22. static::deleting(function($attachment) {
  23. // delete associated file from storage
  24. Storage::disk('public')->delete($attachment->uid);
  25. });
  26. }
  27.  
  28. return [
  29. // Allowed file types with . prefix
  30. 'allowed' => '.pdf,.doc,.xls,.docx,.xlsx,.jpg,.png,.gif,.jpeg',
  31. // Max file size in KB
  32. 'max_size' => 5000
  33. ];
  34. }
Add Comment
Please, Sign In to add comment