Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

pixelfed/pixelfed

6813 stars
2 code files
View pixelfed/pixelfed on GitHub

app/Observers/AvatarObserver.php

Open in GitHub
use 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 GitHub
use 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)
//
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.