-
app/Observers/AvatarObserver.php
Open in GitHubuse App\Avatar; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use App\Services\AccountService; class AvatarObserver { public function updated(Avatar $avatar) { AccountService::del($avatar->profile_id); } public function deleting(Avatar $avatar) { $path = storage_path('app/'.$avatar->media_path); if( is_file($path) && $avatar->media_path != 'public/avatars/default.png' && $avatar->media_path != 'public/avatars/default.jpg' ) { @unlink($path); } if($avatar->cdn_url) { $disk = Storage::disk(config('filesystems.cloud')); $base = Str::startsWith($avatar->media_path, 'cache/avatars/'); if($base && $disk->exists($avatar->media_path)) { $disk->delete($avatar->media_path); } } AccountService::del($avatar->profile_id); } }
-
app/Providers/AppServiceProvider.php
Open in GitHubuse App\Observers\{ AvatarObserver, LikeObserver, NotificationObserver, ModLogObserver, ProfileObserver, StatusHashtagObserver, UserObserver, UserFilterObserver, }; use App\{ Avatar, Like, Notification, ModLog, Profile, StatusHashtag, User, UserFilter }; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function boot() { // Avatar::observe(AvatarObserver::class) // } // }