Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class Attachment extends Model
- {
- protected $guarded = [];
- protected $appends = ['url'];
- public function attachable()
- {
- return $this->morphTo();
- }
- public function getUrlAttribute()
- {
- return Storage::url($this->uid);
- }
- public static function boot()
- {
- parent::boot();
- static::deleting(function($attachment) {
- // delete associated file from storage
- Storage::disk('public')->delete($attachment->uid);
- });
- }
- return [
- // Allowed file types with . prefix
- 'allowed' => '.pdf,.doc,.xls,.docx,.xlsx,.jpg,.png,.gif,.jpeg',
- // Max file size in KB
- 'max_size' => 5000
- ];
- }
Add Comment
Please, Sign In to add comment