Skip to content

Commit

Permalink
Format e-mail addresses and phone numbers as links, adjust margins fo…
Browse files Browse the repository at this point in the history
…r login and registration form (#72)
  • Loading branch information
patrickrobrecht authored Feb 16, 2025
1 parent 7ba776a commit deed3a6
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 36 deletions.
2 changes: 2 additions & 0 deletions app/Models/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\QueryBuilder\BuildsQueryFromRequest;
use App\Models\QueryBuilder\SortOptions;
use App\Models\Traits\HasAddress;
use App\Models\Traits\HasPhone;
use App\Options\DeletedFilter;
use App\Options\FilterValue;
use App\Options\FormElementType;
Expand Down Expand Up @@ -53,6 +54,7 @@ class Booking extends Model
use BuildsQueryFromRequest;
use HasAddress;
use HasFactory;
use HasPhone;
use SoftDeletes;

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Traits/HasAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function addressBlock(): Attribute
$this->streetLine,
$this->cityLine,
$this->country,
], fn (?string $line) => $line !== null && trim($line) !== ''));
], static fn (?string $line) => $line !== null && trim($line) !== ''));
}

public function addressLine(): Attribute
Expand Down
27 changes: 27 additions & 0 deletions app/Models/Traits/HasPhone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Models\Traits;

use Illuminate\Database\Eloquent\Casts\Attribute;

/**
* @property-read ?string $phone_link {@see self::phoneLink()}
*/
trait HasPhone
{
public function phoneLink(): Attribute
{
return Attribute::get(function () {
if (!isset($this->phone)) {
return null;
}

$phone = preg_replace('/[^\d\+]/', '', $this->phone);
if (!str_starts_with($phone, '+')) {
$phone = '+49' . substr($phone, str_starts_with($phone, '0') ? 1 : 0);
}

return 'tel:' . $phone;
});
}
}
2 changes: 2 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\QueryBuilder\SortOptions;
use App\Models\Traits\FiltersByRelationExistence;
use App\Models\Traits\HasAddress;
use App\Models\Traits\HasPhone;
use App\Models\Traits\Searchable;
use App\Notifications\AccountCreatedNotification;
use App\Notifications\ResetPasswordNotification;
Expand Down Expand Up @@ -61,6 +62,7 @@ class User extends Authenticatable implements MustVerifyEmail
use HasAddress;
use HasApiTokens;
use HasFactory;
use HasPhone;
use Notifiable;
use Searchable;

Expand Down
7 changes: 3 additions & 4 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
<x-bs::form.field name="email" type="email" required autofocus>{{ __('E-mail') }}</x-bs::form.field>
<x-bs::form.field name="password" type="password" required
autocomplete="current-password">{{ __('Password') }}</x-bs::form.field>
<x-bs::form.field name="remember" type="checkbox" :options="[1 => __('Remember me')]" cast="int"/>

<x-form.button class="w-100">{{ __('Login') }}</x-form.button>
<x-bs::form.field name="remember" type="checkbox" :options="\Portavice\Bladestrap\Support\Options::one(__('Remember me'))"/>
<x-bs::button class="mt-3 w-100">{{ __('Login') }}</x-bs::button>

@if (\Illuminate\Support\Facades\Route::has('password.request'))
<div class="small mt-5">
<div class="small mt-3">
<a href="{{ route('password.request') }}">
{{ __('Forgot your password?') }}
</a>
Expand Down
6 changes: 4 additions & 2 deletions resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<x-bs::form.field name="password" type="password" required
autocomplete="current-password">{{ __('Password') }}</x-bs::form.field>
<x-bs::form.field name="password_confirmation" type="password" required>{{ __('Confirm password') }}</x-bs::form.field>
<x-bs::form.field name="remember" type="checkbox" :options="[1 => __('Remember me')]" cast="int"/>
@php
$termsAndConditions = config('app.urls.terms_and_conditions');
@endphp
Expand All @@ -35,7 +34,10 @@
<x-bs::form.field name="terms_and_conditions" type="checkbox" :options="$option" :allow-html="true"/>
@endif

<x-form.button class="w-100">{{ __('Register') }}</x-form.button>
<x-bs::button @class([
'mt-3' => $termsAndConditions,
'w-100',
])>{{ __('Register') }}</x-bs::button>
</x-bs::form>
</x-card.centered>
@endsection
8 changes: 6 additions & 2 deletions resources/views/bookings/booking_index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@
@endisset
<x-bs::list.item>
<i class="fa fa-fw fa-at"></i>
{{ $booking->email }}
<a href="mailto:{{ $booking->email }}">{{ $booking->email }}</a>
</x-bs::list.item>
<x-bs::list.item>
<i class="fa fa-fw fa-phone"></i>
{{ $booking->phone ?? __('none') }}
@isset($booking->phone)
<a href="{{ $booking->phone_link }}">{{ $booking->phone }}</a>
@else
{{ __('none') }}
@endisset
</x-bs::list.item>
<x-bs::list.item>
<i class="fa fa-fw fa-road"></i>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/card/centered.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="row justify-content-center">
<div class="col-sm-8 col-lg-6">
<div class="card border-primary border-2">
<div class="card">
<div class="card-header">@yield('title')</div>
<div class="card-body">
{{ $slot }}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/locations/location_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
</x-bs::button.group>
</x-bs::form>

<x-text.timestamp :model="$location ?? null" />
<x-text.timestamp :model="$location ?? null"/>
@endsection
4 changes: 2 additions & 2 deletions resources/views/locations/location_index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</div>
</x-form.filter>

<x-alert.count class="mt-3" :count="$locations->total()" />
<x-alert.count class="mt-3" :count="$locations->total()"/>

<div class="row my-3">
@foreach($locations as $location)
Expand Down Expand Up @@ -107,7 +107,7 @@
</div>
@endcan
<div class="card-footer">
<x-text.updated-human-diff :model="$location" />
<x-text.updated-human-diff :model="$location"/>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/organizations/organization_index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<h2 class="card-title">
<a href="{{ $organization->getRoute() }}">{{ $organization->name }}</a>
</h2>
<x-badge.active-status :active="$organization->status" />
<x-badge.active-status :active="$organization->status"/>
</div>
<x-bs::list :flush="true">
<x-bs::list.item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@
</x-bs::button.group>
</x-bs::form>

<x-text.timestamp :model="$token ?? null" />
<x-text.timestamp :model="$token ?? null"/>
@endsection
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@endcan
</x-bs::button.group>

<x-alert.count class="mt-3" :count="$user->tokens->count()" />
<x-alert.count class="mt-3" :count="$user->tokens->count()"/>

<div class="row my-3">
@foreach($user->tokens as $token)
Expand All @@ -44,7 +44,7 @@
<x-button.edit href="{{ route('personal-access-tokens.edit', $token) }}"/>
@endcan
@can('forceDelete', $token)
<x-button.delete form="delete-{{ $token->id }}" />
<x-button.delete form="delete-{{ $token->id }}"/>
<x-bs::form id="delete-{{ $token->id }}" method="DELETE"
action="{{ route('personal-access-tokens.destroy', $token) }}"/>
@endcan
Expand Down
4 changes: 2 additions & 2 deletions resources/views/users/shared/user_profile_data.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<span class="text-nowrap me-3"><i class="fa fa-fw fa-cake-candles" title="{{ __('Date of birth') }}"></i> {{ formatDate($user->date_of_birth) }}</span>
@endisset
@isset($user->phone)
<span class="text-nowrap me-3"><i class="fa fa-fw fa-phone" title="{{ __('Phone number') }}"></i> {{ $user->phone }}</span>
<span class="text-nowrap me-3"><i class="fa fa-fw fa-phone" title="{{ __('Phone number') }}"></i> <a href="{{ $user->phone_link }}">{{ $user->phone }}</a></span>
@endisset
<span class="text-nowrap me-3"><i class="fa fa-fw fa-at" title="{{ __('E-mail') }}"></i> {{ $user->email }}
<span class="text-nowrap me-3"><i class="fa fa-fw fa-at" title="{{ __('E-mail') }}"></i> <a href="mailto:{{ $user->email }}">{{ $user->email }}</a>
@isset($user->email_verified_at)
<x-bs::badge variant="success">{{ __('verified') }}</x-bs::badge>
@else
Expand Down
2 changes: 1 addition & 1 deletion resources/views/users/user_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@
</x-bs::button.group>
</x-bs::form>

<x-text.timestamp :model="$editedUser ?? null" />
<x-text.timestamp :model="$editedUser ?? null"/>
@endsection
6 changes: 3 additions & 3 deletions resources/views/users/user_index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@
<x-bs::list.item>
<span class="text-nowrap"><i class="fa fa-fw fa-phone"></i> {{ __('Phone number') }}</span>
<x-slot:end>
<span class="text-end">{{ $user->phone }}</span>
<span class="text-end"><a href="{{ $user->phone_link }}">{{ $user->phone }}</a></span>
</x-slot:end>
</x-bs::list.item>
@endisset
<x-bs::list.item>
<span class="text-nowrap"><i class="fa fa-fw fa-at"></i> {{ __('E-mail') }}</span>
<x-slot:end>
<span class="text-end">
{{ $user->email }}
<a href="mailto:{{ $user->email }}">{{ $user->email }}</a>
@isset($user->email_verified_at)
<x-bs::badge variant="success">{{ __('verified') }}</x-bs::badge>
@else
Expand Down Expand Up @@ -160,7 +160,7 @@
</div>
@endcan
<div class="card-footer">
<x-text.updated-human-diff :model="$user" />
<x-text.updated-human-diff :model="$user"/>
</div>
</div>
</div>
Expand Down
26 changes: 13 additions & 13 deletions routes/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@

Route::middleware('guest')->group(function () {
Route::get('register', [RegisteredUserController::class, 'create'])
->name('register');
->name('register');
Route::post('register', [RegisteredUserController::class, 'store']);

Route::get('login', [AuthenticatedSessionController::class, 'create'])
->name('login');
->name('login');
Route::post('login', [AuthenticatedSessionController::class, 'store']);

Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])
->name('password.request');
->name('password.request');
Route::post('forgot-password', [PasswordResetLinkController::class, 'store'])
->name('password.email');
->name('password.email');

Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])
->name('password.reset');
->name('password.reset');
Route::post('reset-password', [NewPasswordController::class, 'store'])
->name('password.update');
->name('password.update');
});

Route::middleware('auth')->group(function () {
Route::get('verify-email', [EmailVerificationPromptController::class, '__invoke'])
->name('verification.notice');
->name('verification.notice');
Route::get('verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke'])
->middleware(['signed', 'throttle:6,1'])
->name('verification.verify');
->middleware(['signed', 'throttle:6,1'])
->name('verification.verify');
Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store'])
->middleware('throttle:6,1')
->name('verification.send');
->middleware('throttle:6,1')
->name('verification.send');

Route::get('confirm-password', [ConfirmablePasswordController::class, 'show'])
->name('password.confirm');
->name('password.confirm');
Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']);

Route::post('logout', [AuthenticatedSessionController::class, 'destroy'])
->name('logout');
->name('logout');
});

0 comments on commit deed3a6

Please sign in to comment.