diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php new file mode 100644 index 0000000..36c6826 --- /dev/null +++ b/app/Http/Resources/UserResource.php @@ -0,0 +1,24 @@ + $this->id, + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, + 'email' => $this->email, + 'email_verified_at' => $this->email_verified_at, + 'image_url' => $this->image_url, + 'roles' => $this->whenLoaded('roles'), + ]; + } +} diff --git a/database/migrations/2024_10_09_122712_add_full_name_column.php b/database/migrations/2024_10_09_122712_add_full_name_column.php index 4219637..8e56433 100644 --- a/database/migrations/2024_10_09_122712_add_full_name_column.php +++ b/database/migrations/2024_10_09_122712_add_full_name_column.php @@ -9,7 +9,7 @@ public function up(): void { Schema::table('users', function (Blueprint $table) { - $table->text('full_name')->virtualAs('CONCAT(first_name, " ", last_name)') + $table->text('full_name')->storedAs('CONCAT(first_name, " ", last_name)') ->after('last_name'); }); } diff --git a/routes/api.php b/routes/api.php index f35f6f8..7cb6789 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,8 +1,11 @@ user(); + return new UserResource( + $request->user() + ); })->middleware('auth:api');