adding a method to also generate an avatar for a user

This commit is contained in:
Brian 2023-12-12 13:58:31 -07:00
parent 5d9f7e3997
commit 9d25befeba
Signed by: brian
GPG Key ID: DE1A5390A3B84CD8

View File

@ -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}"
]);
}
}