Merge remote-tracking branch 'origin/#4-users-crud' into #4-users-crud
# Conflicts: # app/Enums/FormOfEmployment.php # app/Models/User.php # resources/js/Pages/Users/Index.vue # routes/web.php
This commit is contained in:
commit
13d166ee81
@ -11,14 +11,16 @@ class CreateUserCommand extends Command
|
|||||||
{
|
{
|
||||||
protected $signature = "user:create
|
protected $signature = "user:create
|
||||||
{email : an email for the user}";
|
{email : an email for the user}";
|
||||||
protected $description = "Creates user";
|
protected $description = "Creates a user";
|
||||||
|
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
$email = $this->argument("email");
|
$email = $this->argument("email");
|
||||||
|
|
||||||
User::factory(["email" => $email])->create();
|
User::factory([
|
||||||
|
"email" => $email,
|
||||||
|
])->create();
|
||||||
|
|
||||||
$this->info("User has been created");
|
$this->info("The user has been created");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,11 @@ enum FormOfEmployment: string
|
|||||||
{
|
{
|
||||||
$cases = collect(FormOfEmployment::cases());
|
$cases = collect(FormOfEmployment::cases());
|
||||||
|
|
||||||
return $cases->map(fn(FormOfEmployment $enum) => [
|
return $cases->map(
|
||||||
"label" => $enum->label(),
|
fn(FormOfEmployment $enum) => [
|
||||||
"value" => $enum->value]
|
"label" => $enum->label(),
|
||||||
|
"value" => $enum->value,
|
||||||
|
],
|
||||||
)->toArray();
|
)->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -49,7 +49,7 @@ class UserController extends Controller
|
|||||||
{
|
{
|
||||||
return inertia("Users/Edit", [
|
return inertia("Users/Edit", [
|
||||||
"user" => new UserFormDataResource($user),
|
"user" => new UserFormDataResource($user),
|
||||||
"employmentForms" => FormOfEmployment::casesToSelect()
|
"employmentForms" => FormOfEmployment::casesToSelect(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ use Toby\Enums\FormOfEmployment;
|
|||||||
* @property string $email
|
* @property string $email
|
||||||
* @property string $avatar
|
* @property string $avatar
|
||||||
* @property FormOfEmployment $employment_form
|
* @property FormOfEmployment $employment_form
|
||||||
* @property Carbon $empoyment_date
|
* @property Carbon $employment_date
|
||||||
*/
|
*/
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
@ -26,8 +26,6 @@ class User extends Authenticatable
|
|||||||
use Notifiable;
|
use Notifiable;
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $perPage = 10;
|
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
"name",
|
"name",
|
||||||
"email",
|
"email",
|
||||||
@ -47,7 +45,7 @@ class User extends Authenticatable
|
|||||||
|
|
||||||
public function scopeSearch(Builder $query, ?string $text): Builder
|
public function scopeSearch(Builder $query, ?string $text): Builder
|
||||||
{
|
{
|
||||||
if ($text == null) {
|
if ($text === null) {
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,13 +6,14 @@ namespace Toby\Observers;
|
|||||||
|
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Toby\Models\User;
|
|
||||||
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
|
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
|
||||||
|
use Toby\Models\User;
|
||||||
|
|
||||||
class UserObserver
|
class UserObserver
|
||||||
{
|
{
|
||||||
public function __construct(protected InitialAvatar $generator)
|
public function __construct(
|
||||||
{
|
protected InitialAvatar $generator,
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function created(User $user): void
|
public function created(User $user): void
|
||||||
@ -38,7 +39,7 @@ class UserObserver
|
|||||||
{
|
{
|
||||||
$path = "avatars/{$user->id}.svg";
|
$path = "avatars/{$user->id}.svg";
|
||||||
|
|
||||||
Storage::put($path, $this->generator->rounded()->background($this->getRandomColor())->generateSvg($user->name));
|
Storage::put($path, $this->generator->rounded()->background($this->getRandomColor())->color("#F4F8FD")->smooth()->generateSvg($user->name));
|
||||||
|
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,19 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
"#F0E9E9",
|
"#475569",
|
||||||
|
"#EA580C",
|
||||||
|
"#EAB308",
|
||||||
|
"#CA8A04",
|
||||||
|
"#84CC16",
|
||||||
|
"#4D7C0F",
|
||||||
|
"#10B981",
|
||||||
|
"#06B6D4",
|
||||||
|
"#4338CA",
|
||||||
|
"#A855F7",
|
||||||
|
"#86198F",
|
||||||
|
"#FB7185",
|
||||||
|
"#EC4899",
|
||||||
|
"#9D174D",
|
||||||
|
"#F43F5E",
|
||||||
];
|
];
|
@ -12,6 +12,8 @@ class DatabaseSeeder extends Seeder
|
|||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
User::factory(35)->create();
|
User::factory(35)->create();
|
||||||
User::factory(["email" => env("USER_EMAIL")])->create();
|
User::factory([
|
||||||
|
"email" => env("USER_EMAIL"),
|
||||||
|
])->create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<form
|
<form
|
||||||
class="border-t border-gray-200 px-6 divide-y"
|
class="border-t border-gray-200 px-6"
|
||||||
@submit.prevent="form.post('/users')"
|
@submit.prevent="form.post('/users')"
|
||||||
>
|
>
|
||||||
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
|
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<form
|
<form
|
||||||
class="border-t border-gray-200 px-6 divide-y"
|
class="border-t border-gray-200 px-6"
|
||||||
@submit.prevent="form.put(`/users/${user.id}`)"
|
@submit.prevent="form.put(`/users/${user.id}`)"
|
||||||
>
|
>
|
||||||
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
|
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
|
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<span
|
<span
|
||||||
class="inline-flex items-center justify-center h-10 w-10 rounded-full bg-blumilk-500"
|
class="inline-flex items-center justify-center h-10 w-10 rounded-full"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
class="h-10 w-10 rounded-full"
|
class="h-10 w-10 rounded-full"
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
class="bg-white rounded-full flex text-sm ring-2 ring-white ring-opacity-20 focus:outline-none focus:ring-opacity-100"
|
class="rounded-full flex text-sm ring-2 ring-white ring-opacity-20 focus:outline-none focus:ring-opacity-100"
|
||||||
>
|
>
|
||||||
<span class="sr-only">Open user menu</span>
|
<span class="sr-only">Open user menu</span>
|
||||||
<img
|
<img
|
||||||
|
23
tests/Feature/UserTest.php
Normal file
23
tests/Feature/UserTest.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Toby\Models\User;
|
||||||
|
|
||||||
|
class UserTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseMigrations;
|
||||||
|
|
||||||
|
public function testUserCanSeeUsersList(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->get("/users")
|
||||||
|
->assertOk();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user