Add avatar image
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
977e427abb
commit
6d204b948e
|
@ -21,7 +21,9 @@ class UserResource extends JsonResource
|
||||||
public function toArray($request): array
|
public function toArray($request): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => $this->name,
|
'firstname' => $this->firstname,
|
||||||
|
'lastname' => $this->lastname,
|
||||||
|
'avatar_url' => $this->getGravatarUrl(),
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
'avatar' => [
|
'avatar' => [
|
||||||
'src' => Storage::url('avatar.png'),
|
'src' => Storage::url('avatar.png'),
|
||||||
|
|
|
@ -22,4 +22,9 @@ class User extends Authenticatable
|
||||||
{
|
{
|
||||||
$this->notify(new ResetPassword($token));
|
$this->notify(new ResetPassword($token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getGravatarUrl(): string
|
||||||
|
{
|
||||||
|
return 'https://www.gravatar.com/avatar/' . hash('sha256', $this->email);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ class UserFactory extends Factory
|
||||||
return [
|
return [
|
||||||
'email' => $this->faker->safeEmail,
|
'email' => $this->faker->safeEmail,
|
||||||
'password' => Hash::make('password'),
|
'password' => Hash::make('password'),
|
||||||
'name' => $this->faker->firstName,
|
'firstname' => $this->faker->firstName,
|
||||||
|
'lastname' => $this->faker->lastName,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\User;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('firstname')->after('name')->nullable();
|
||||||
|
$table->string('lastname')->after('name')->nullable();
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (User::get() as $user) {
|
||||||
|
$user->update([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (DB::table('users')->get() as $user) {
|
||||||
|
[$firstname, $lastname] = explode(' ', $user->name);
|
||||||
|
DB::table('users')->where('id', $user->id)->update(['firstname' => $firstname, 'lastname' => $lastname]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('firstname')->nullable(false)->change();
|
||||||
|
$table->string('lastname')->nullable(false)->change();
|
||||||
|
$table->dropColumn('name');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('name');
|
||||||
|
});
|
||||||
|
foreach (DB::table('users')->get() as $user) {
|
||||||
|
DB::table('users')->where('id', $user->id)->update(['name' => $user->firstname . ' ' . $user->lastname]);
|
||||||
|
}
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('firstname');
|
||||||
|
$table->dropColumn('lastname');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
|
@ -5,7 +5,7 @@
|
||||||
<page-title>{{ title }}</page-title>
|
<page-title>{{ title }}</page-title>
|
||||||
<slot name="toolbar"></slot>
|
<slot name="toolbar"></slot>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center space-x-2 ml-2">
|
<div class="flex items-center space-x-4 ml-2">
|
||||||
<a v-if="$attrs.onClose" href="#" class="btn label btn-primary-light icon" @click.prevent="$emit('close')">
|
<a v-if="$attrs.onClose" href="#" class="btn label btn-primary-light icon" @click.prevent="$emit('close')">
|
||||||
<ui-sprite class="w-3 h-3" src="close"></ui-sprite>
|
<ui-sprite class="w-3 h-3" src="close"></ui-sprite>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -12,6 +12,12 @@
|
||||||
</template>
|
</template>
|
||||||
<template #right>
|
<template #right>
|
||||||
<slot name="right"></slot>
|
<slot name="right"></slot>
|
||||||
|
<div class="flex items-center space-x-2">
|
||||||
|
<div class="rounded-full overflow-hidden border-2 border-solid border-gray-300">
|
||||||
|
<img :src="$page.props.auth.user.avatar_url" class="w-8 h-8 object-cover" />
|
||||||
|
</div>
|
||||||
|
<div class="text-gray-300" v-text="`${$page.props.auth.user.firstname} ${$page.props.auth.user.lastname}`"></div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</page-header>
|
</page-header>
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,19 @@ class DashboardTest extends TestCase
|
||||||
$this->assertInertiaHas('Example', $response, 'blocks.0.title');
|
$this->assertInertiaHas('Example', $response, 'blocks.0.title');
|
||||||
$this->assertInertiaHas('exa', $response, 'blocks.0.component');
|
$this->assertInertiaHas('exa', $response, 'blocks.0.component');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItDisplaysUserAvatar(): void
|
||||||
|
{
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
|
||||||
|
$this->login()->loginNami();
|
||||||
|
auth()->user()->update(['firstname' => 'Bob', 'lastname' => 'Dylan', 'email' => 'max@email.com']);
|
||||||
|
|
||||||
|
$this->get('/')
|
||||||
|
->assertInertiaPath('auth.user.firstname', 'Bob')
|
||||||
|
->assertInertiaPath('auth.user.avatar_url', 'https://www.gravatar.com/avatar/' . hash('sha256', 'max@email.com'))
|
||||||
|
->assertInertiaPath('auth.user.lastname', 'Dylan');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExampleBlock extends Block
|
class ExampleBlock extends Block
|
||||||
|
|
Loading…
Reference in New Issue