Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Delete the users profile picture #399

Merged
merged 10 commits into from
Oct 27, 2020
11 changes: 7 additions & 4 deletions src/HasProfilePhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Laravel\Jetstream\Features;

trait HasProfilePhoto
{
Expand Down Expand Up @@ -35,11 +36,13 @@ public function updateProfilePhoto(UploadedFile $photo)
*/
public function deleteProfilePhoto()
{
Storage::disk($this->profilePhotoDisk())->delete($this->profile_photo_path);
if (Features::managesProfilePhotos()) {
Storage::disk($this->profilePhotoDisk())->delete($this->profile_photo_path);

$this->forceFill([
'profile_photo_path' => null,
])->save();
$this->forceFill([
'profile_photo_path' => null,
])->save();
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions stubs/app/Actions/Jetstream/DeleteUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class DeleteUser implements DeletesUsers
*/
public function delete($user)
{
$user->deleteProfilePhoto();
lostdesign marked this conversation as resolved.
Show resolved Hide resolved
$user->delete();
}
}
2 changes: 1 addition & 1 deletion stubs/app/Actions/Jetstream/DeleteUserWithTeams.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function delete($user)
{
DB::transaction(function () use ($user) {
$this->deleteTeams($user);

$user->deleteProfilePhoto();
lostdesign marked this conversation as resolved.
Show resolved Hide resolved
$user->delete();
});
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace Laravel\Jetstream\Tests\Fixtures;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
use HasApiTokens, HasTeams;
use HasApiTokens, HasTeams, HasProfilePhoto;

/**
* The attributes that aren't mass assignable.
Expand Down