Skip to content

Commit

Permalink
trait to set profile photo from url
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Butcher committed Feb 4, 2021
1 parent c8f51ae commit 95fbdec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/SetsProfilePhotoFromUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace JoelButcher\Socialstream;

use Illuminate\Http\UploadedFile;

trait SetsProfilePhotoFromUrl
{
/**
* Sets the users profile photo from a URL.
*
* @param string $url
* @return void
*/
public function setProfilePhotoFromUrl(string $url)
{
$name = pathinfo($url)['basename'];
file_put_contents($file = '/tmp/'.$name, file_get_contents($url));
$this->updateProfilePhoto(new UploadedFile($file, $name));
}
}
2 changes: 2 additions & 0 deletions stubs/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use JoelButcher\Socialstream\HasConnectedAccounts;
use JoelButcher\Socialstream\SetsProfilePhotoFromUrl;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
Expand All @@ -19,6 +20,7 @@ class User extends Authenticatable
use HasTeams;
use HasConnectedAccounts;
use Notifiable;
use SetsProfilePhotoFromUrl;
use TwoFactorAuthenticatable;

/**
Expand Down

0 comments on commit 95fbdec

Please sign in to comment.