Skip to content

Commit

Permalink
add user description
Browse files Browse the repository at this point in the history
  • Loading branch information
butburg committed Sep 12, 2024
1 parent b1df01a commit 58213d5
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .timetracker

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ public function updateName(ProfileUpdateRequest $request): RedirectResponse {
session()->flash('notif.success', 'Your username updated successfully!');
return Redirect::route('profile.edit');
}

public function updateDescription(ProfileUpdateRequest $request): RedirectResponse {
$user = Auth::user();
$description = $request->validated()['description'];

$user->description = $description;
$user->save();

session()->flash('notif.success', 'Your description updated successfully!');
return Redirect::route('profile.edit');
}

public function updateEmail(ProfileUpdateRequest $request): RedirectResponse {

$user = Auth::user();
Expand Down
4 changes: 4 additions & 0 deletions src/app/Http/Requests/ProfileUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public function rules(): array {
$rules['name'] = ['required', 'string', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)];
}

if ($this->routeIs('profile.updateDescription')) {
$rules['description'] = ['nullable', 'string', 'max:500'];
}

if ($this->routeIs('profile.updateEmail')) {
$rules['email'] = ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)];
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class User extends Authenticatable implements MustVerifyEmail {
*
* @var array<int, string>
*/
protected $fillable = ['name', 'email', 'password', 'profile_image', 'usertype'];
protected $fillable = ['name', 'email', 'password', 'profile_image', 'usertype', 'description'];

public function posts() {
return $this->hasMany(Post::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void {
Schema::table('users', function (Blueprint $table) {
$table->text('description')->nullable()->after('usertype');
});
}

/**
* Reverse the migrations.
*/
public function down(): void {
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('description');
});
}
};
11 changes: 10 additions & 1 deletion src/resources/views/profile/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ class="italic text-white">{{ Session::get('notif.success') }}</span>
</x-slot>

<div class="py-6">

<div class="mx-auto max-w-7xl space-y-6 sm:px-6 lg:px-8">
<!-- New Section for Profile Image Update -->
<div
class="bg-c-primary/40 p-4 text-c-text shadow sm:rounded-lg sm:p-8">
class="bg-c-primary/10 p-4 text-c-text shadow sm:rounded-lg sm:p-8">
<div class="max-w-xl">
@include('profile.partials.update-profile-image-form')
</div>
</div>

<div
class="bg-c-primary/40 p-4 text-c-text shadow sm:rounded-lg sm:p-8">
<div class="max-w-xl">
@include('profile.partials.update-description-form')
</div>
</div>

<div
class="bg-c-primary/10 p-4 text-c-text shadow sm:rounded-lg sm:p-8">
<div class="max-w-xl">
Expand Down
11 changes: 11 additions & 0 deletions src/resources/views/profile/partials/display-description.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<section>
<header>
<h2 class="text-lg font-medium text-content-text text-gray-400">
{{ __('About Me') }}
</h2>
</header>

<p class="mt-2 text-sm text-gray-400">
{{ $user->description ?? __('No description provided.') }}
</p>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<section>
<header>
<h2 class="text-lg font-medium text-content-text">
{{ __('Update Description') }}
</h2>

<p class="mt-1 text-sm text-gray-300">
{{ __('Write a short description about yourself.') }}
</p>
</header>

<form method="post" action="{{ route('profile.updateDescription') }}" class="mt-6 space-y-6">
@csrf
@method('patch')

<div>
<x-input-label for="description" :value="__('Description')" />
<textarea id="description" name="description" rows="4" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm">{{ old('description', $user->description) }}</textarea>
<x-input-error :messages="$errors->updateDescription->get('description')" class="mt-2" />
</div>

<div class="flex items-center gap-4">
<x-primary-button>{{ __('Save') }}</x-primary-button>

@if (session('status') === 'description-updated')
<p x-data="{ show: true }" x-show="show" x-transition x-init="setTimeout(() => show = false, 2000)" class="text-sm text-gray-600">{{ __('Saved.') }}</p>
@endif
</div>
</form>
</section>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<section>
<header>
<h2 class="text-content-text text-lg font-medium">
{{ __('Update profile image') }}
{{ __('Update Profile Image') }}
</h2>
<p class="mt-1 text-sm text-gray-300">
{{ __('Make yourself better reconizable to others.') }}
Expand Down
16 changes: 15 additions & 1 deletion src/resources/views/profile/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class="mb-6 overflow-hidden bg-c-primary/10 p-6 shadow-sm sm:rounded-lg">
'user' => $user,
])

@include(
'profile.partials.display-description',
['user' => $user]
)

<!-- Display "Last seen" information only -->
@php
// max needs timestamps, so get these compare and than decide which time object to choose
Expand All @@ -53,13 +58,22 @@ class="mb-6 overflow-hidden bg-c-primary/10 p-6 shadow-sm sm:rounded-lg">
$mostRecentUpdatedAt = $postUpdatedAt
? max($userUpdatedAt, $postUpdatedAt)
: $userUpdatedAt;
// for showing time if seesion active
$lastActivity = \Carbon\Carbon::parse(
$user->session->last_activity,
);
@endphp

<div class="text-sm text-gray-400">
<p>
<strong>Seen:</strong>
@if ($user->session)
{{ \Carbon\Carbon::parse($user->session->last_activity)->diffInMinutes() }}
@if ($lastActivity->diffInMinutes() < 3)
Active
@else
{{ $lastActivity->diffForHumans() }}
@endif
@else
{{ $mostRecentUpdatedAt->format('d.m.y') }}
@endif
Expand Down
3 changes: 3 additions & 0 deletions src/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
Route::patch('/profile/update-name', [ProfileController::class, 'updateName'])
->name('profile.updateName');

Route::patch('/profile/update-description', [ProfileController::class, 'updateDescription'])
->name('profile.updateDescription');

Route::patch('/profile/update-email', [ProfileController::class, 'updateEmail'])
->name('profile.updateEmail');

Expand Down

0 comments on commit 58213d5

Please sign in to comment.