adding a method to also generate an avatar for a user
This commit is contained in:
parent
5d9f7e3997
commit
9d25befeba
@ -6,6 +6,7 @@ use App\Models\Language;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Jetstream\Features;
|
||||
|
||||
@ -71,4 +72,25 @@ class UserFactory extends Factory
|
||||
'ownedTeams'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the user should have an avatar image.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withAvatar()
|
||||
{
|
||||
if (! Features::enabled(Features::profilePhotos())) {
|
||||
return $this->state([]);
|
||||
}
|
||||
|
||||
$imageUrl = 'https://avatars.test/';
|
||||
$imageContents = file_get_contents($imageUrl);
|
||||
$imageName = md5($imageContents) . '.jpg';
|
||||
Storage::put("public/avatars/{$imageName}", $imageContents);
|
||||
|
||||
return $this->state([
|
||||
'profile_photo_path' => "avatars/{$imageName}"
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user