rhyslees / jetstream-user-timezone
This is my package jetstream-user-timezone
Requires
- php: ^8.1
- illuminate/contracts: ^9.0
- livewire/livewire: ^2.10
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- laravel/pint: ^1.3
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- pestphp/pest-plugin-livewire: ^1.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-10-09 22:44:16 UTC
README
This package adds a simple way for you to add a user timezone selection field to your user profile page in jetstream.
- Validation included
Note: Livewire is currently the only supported stack
Installation
You can install the package via composer:
composer require rhyslees/jetstream-user-timezone
You can publish and run the migrations with:
php artisan vendor:publish --tag="jetstream-user-timezone-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="jetstream-user-timezone-config"
Optionally, you can publish the views using
php artisan vendor:publish --tag="jetstream-user-timezone-views"
Usage
Goto resources/views/profile/show.blade.php
and and the following between the information form and password form.
@livewire('jetstream-user-timezone::update-timezone-form') <x-jet-section-border />
It should look like this:
... @if (Laravel\Fortify\Features::canUpdateProfileInformation()) @livewire('profile.update-profile-information-form') <x-jet-section-border /> @endif @livewire('jetstream-user-timezone::update-timezone-form') <x-jet-section-border /> @if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::updatePasswords())) <div class="mt-10 sm:mt-0"> @livewire('profile.update-password-form') </div> <x-jet-section-border /> @endif ...
Finally add the following to your User
model:
use RhysLees\JetstreamUserTimezone\Traits\HasTimezone; class User extends Authenticatable { use HasTimezone; ... }
What timezones are shown?
Under the hood, we use php's default timezone_identifiers_list()
function to return all avalible timezones to the user.
If you would like to specify what timezone to use, you can fill the array with your choice of options in config/jetstream-user-timezone.php
in the timezones array.
Note: you must ensure you add valid timezones to the array or validation will fail for users.
For a list of valid timezones please see: https://www.php.net/manual/en/timezones.php
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.