From 106283903ea199ab728a4f8bc11ee4ecb7af0714 Mon Sep 17 00:00:00 2001 From: Irwan Cahyono Date: Tue, 17 Mar 2026 09:58:11 +0700 Subject: [PATCH] update api scramble telescope --- app/Http/Controllers/Api/AuthController.php | 8 +- .../Api/DesaKelurahanController.php | 59 +++-- .../Controllers/Api/KecamatanController.php | 53 +++-- .../Controllers/Api/ProfileController.php | 61 ++++- .../Controllers/Web/KecamatanController.php | 4 +- app/Http/Resources/ProfileResource.php | 36 +++ app/Http/Resources/UserResource.php | 25 +++ .../Wilayah/DesaKelurahanResource.php | 24 ++ .../Wilayah/KabupatenKotaResource.php | 26 +++ .../Resources/Wilayah/KecamatanResource.php | 26 +++ .../Resources/Wilayah/ProvinsiResource.php | 23 ++ app/Models/Profile.php | 6 +- app/Models/Wilayah/Kecamatan.php | 4 +- app/Providers/AppServiceProvider.php | 11 + app/Providers/TelescopeServiceProvider.php | 65 ++++++ bootstrap/providers.php | 1 + composer.json | 2 + config/scramble.php | 136 +++++++++++ config/telescope.php | 212 ++++++++++++++++++ ..._221143_create_telescope_entries_table.php | 70 ++++++ routes/api.php | 6 +- 21 files changed, 797 insertions(+), 61 deletions(-) create mode 100644 app/Http/Resources/ProfileResource.php create mode 100644 app/Http/Resources/UserResource.php create mode 100644 app/Http/Resources/Wilayah/DesaKelurahanResource.php create mode 100644 app/Http/Resources/Wilayah/KabupatenKotaResource.php create mode 100644 app/Http/Resources/Wilayah/KecamatanResource.php create mode 100644 app/Http/Resources/Wilayah/ProvinsiResource.php create mode 100644 app/Providers/TelescopeServiceProvider.php create mode 100644 config/scramble.php create mode 100644 config/telescope.php create mode 100644 database/migrations/2026_03_16_221143_create_telescope_entries_table.php diff --git a/app/Http/Controllers/Api/AuthController.php b/app/Http/Controllers/Api/AuthController.php index bf636b2..787498a 100644 --- a/app/Http/Controllers/Api/AuthController.php +++ b/app/Http/Controllers/Api/AuthController.php @@ -11,6 +11,8 @@ use Illuminate\Support\Facades\Hash; use App\Models\User; use App\Models\Profile; +use App\Http\Resources\UserResource; + class AuthController extends Controller { public function login(Request $request): JSONResponse @@ -41,7 +43,7 @@ class AuthController extends Controller { $credentials = $request->validate([ 'name' => ['required', 'string', 'max:255'], - 'email' => ['required', 'email'], + 'email' => ['required', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'string', 'min:8', 'confirmed'], 'role' => ['string'], ]); @@ -58,6 +60,8 @@ class AuthController extends Controller 'email' => $credentials['email'], 'role' => $credentials['role'], 'user_id' => $user->id, + 'created_by' => $user->id, + 'updated_by' => $user->id, ]); if (!Auth::attempt($credentials)) { @@ -79,7 +83,7 @@ class AuthController extends Controller public function me(Request $request): JSONResponse { - return response()->json($request->user()); + return response()->json(new UserResource($request->user())); } public function logout(Request $request): JSONResponse diff --git a/app/Http/Controllers/Api/DesaKelurahanController.php b/app/Http/Controllers/Api/DesaKelurahanController.php index aa33925..ee0d285 100644 --- a/app/Http/Controllers/Api/DesaKelurahanController.php +++ b/app/Http/Controllers/Api/DesaKelurahanController.php @@ -6,40 +6,55 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Models\Wilayah\DesaKelurahan; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Resources\Json\AnonymousResourceCollection; +use App\Http\Resources\Wilayah\DesaKelurahanResource; +use App\Http\Resources\Wilayah\DesaKelurahanCollectionResource; class DesaKelurahanController extends Controller { /** * Display a listing of the resource. */ - public function index(Request $request): JsonResponse + public function index(Request $request): AnonymousResourceCollection { - $size = +$request->get('size') ?: 10; + $size = $request->integer('size') ?: 10; - $master = DesaKelurahan::query(); + $master = DesaKelurahan::with('kecamatan') + ->when($request->search, function ($q, $search) { + $search = strtolower($search); + $q->where(function ($query) use ($search) { + $query->whereRaw('lower(kode) like ?', ["%{$search}%"]) + ->orWhereRaw('lower(nama) like ?', ["%{$search}%"]); + }); + }) + ->when($request->kecamatan_id, fn($q,$v) => $q->where('kecamatan_id',$v)) + ->when($request->kabupaten_kota_id, fn ($q, $v) => + $q->whereHas('kecamatan', fn ($k) => + $k->where('kabupaten_kota_id', $v) + ) + ) + ->when($request->provinsi_id, fn ($q, $v) => + $q->whereHas('kecamatan.kabupatenkota', fn ($k) => + $k->where('provinsi_id', $v) + ) + ); - if ($request->has('search')) { - $s = $request->get('search'); - $s = strtolower($s); - $master->where(function($query) use ($s) { - $query->whereRaw('lower(kode) like (?)',["%{$s}%"]) - ->orWhereRaw('lower(nama) like (?)',["%{$s}%"]); - }); - } - if ($request->has('sort')) { - $order = $request->get('sort'); - $d = substr($order, 0, 1); - $dir = $d === '-' ? 'desc' : 'asc'; - $order = $d === '-' ? substr($order, 1) : $order; - $master->orderBy($order, $dir); - } - if ($request->has('kecamatan_id')) { - $master->where('kecamatan_id', $request->get('kecamatan_id')); + if ($request->filled('sort')) { + $dir = str_starts_with($request->sort, '-') ? 'desc' : 'asc'; + $column = ltrim($request->sort, '-'); + + $allowed = ['id', 'kode', 'nama']; + + if (in_array($column, $allowed)) { + $master->orderBy($column, $dir); + } + } else { + $master->orderBy('kode', 'asc'); } $masterList = $master->paginate($size); - return response()->json($masterList); + return DesaKelurahanResource::collection($masterList); } /** @@ -63,7 +78,7 @@ class DesaKelurahanController extends Controller */ public function show(string $id): JsonResponse { - return response()->json(DesaKelurahan::findOrFail($id)); + return response()->json(DesaKelurahanResource::make(DesaKelurahan::with('kecamatan')->findOrFail($id))); } /** diff --git a/app/Http/Controllers/Api/KecamatanController.php b/app/Http/Controllers/Api/KecamatanController.php index 3210701..fd189bc 100644 --- a/app/Http/Controllers/Api/KecamatanController.php +++ b/app/Http/Controllers/Api/KecamatanController.php @@ -6,40 +6,49 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Models\Wilayah\Kecamatan; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Resources\Json\AnonymousResourceCollection; +use App\Http\Resources\Wilayah\KecamatanResource; class KecamatanController extends Controller { /** * Display a listing of the resource. */ - public function index(Request $request): JsonResponse + public function index(Request $request): AnonymousResourceCollection { - $size = +$request->get('size') ?: 10; + $size = $request->get('size') ?: 10; - $master = Kecamatan::query(); + $master = Kecamatan::with('kabupatenKota') + ->when($request->search, function ($q, $search) { + $search = strtolower($search); + $q->where(function ($query) use ($search) { + $query->whereRaw('lower(kode) like ?', ["%{$search}%"]) + ->orWhereRaw('lower(nama) like ?', ["%{$search}%"]); + }); + }) + ->when($request->kabupaten_kota_id, fn($q,$v) => $q->where('kabupaten_kota_id',$v)) + ->when($request->provinsi_id, fn ($q, $v) => + $q->whereHas('kabupatenKota.provinsi', fn ($k) => + $k->where('provinsi_id', $v) + ) + ); - if ($request->has('search')) { - $s = $request->get('search'); - $s = strtolower($s); - $master->where(function($query) use ($s) { - $query->whereRaw('lower(kode) like (?)',["%{$s}%"]) - ->orWhereRaw('lower(nama) like (?)',["%{$s}%"]); - }); - } - if ($request->has('sort')) { - $order = $request->get('sort'); - $d = substr($order, 0, 1); - $dir = $d === '-' ? 'desc' : 'asc'; - $order = $d === '-' ? substr($order, 1) : $order; - $master->orderBy($order, $dir); - } - if ($request->has('kabupaten_kota_id')) { - $master->where('kabupaten_kota_id', $request->get('kabupaten_kota_id')); + if ($request->filled('sort')) { + $dir = str_starts_with($request->sort, '-') ? 'desc' : 'asc'; + $column = ltrim($request->sort, '-'); + + $allowed = ['id', 'kode', 'nama']; + + if (in_array($column, $allowed)) { + $master->orderBy($column, $dir); + } + } else { + $master->orderBy('kode', 'asc'); } $masterList = $master->paginate($size); - return response()->json($masterList); + return KecamatanResource::collection($masterList); } /** @@ -63,7 +72,7 @@ class KecamatanController extends Controller */ public function show(string $id): JsonResponse { - return response()->json(Kecamatan::findOrFail($id)); + return response()->json(KecamatanResource::make(Kecamatan::with('kabupatenKota')->findOrFail($id))); } /** diff --git a/app/Http/Controllers/Api/ProfileController.php b/app/Http/Controllers/Api/ProfileController.php index 9a69b3d..4026cff 100644 --- a/app/Http/Controllers/Api/ProfileController.php +++ b/app/Http/Controllers/Api/ProfileController.php @@ -6,6 +6,11 @@ use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Models\Profile; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; +use Illuminate\Http\JsonResponse; +use Symfony\Component\HttpFoundation\BinaryFileResponse; + +use App\Http\Resources\ProfileResource; class ProfileController extends Controller { @@ -36,10 +41,10 @@ class ProfileController extends Controller /** * Display the specified resource. */ - public function show() + public function show(string $id): JSONResponse { - $profile = Profile::where('user_id', Auth::id())->first(); - return response()->json($profile); + $profile = Profile::with('desaKelurahan')->where('user_id', Auth::id())->first(); + return response()->json(new ProfileResource($profile)); } /** @@ -53,19 +58,44 @@ class ProfileController extends Controller /** * Update the specified resource in storage. */ - public function update(Request $request) + public function update(Request $request, string $id): JSONResponse { $validated = $request->validate([ 'nama' => ['required', 'string', 'max:255'], - 'email' => ['required', 'email'], + 'email' => ['required', 'email', 'max:255', 'unique:users,email,' . Auth::id()], 'telepon' => ['nullable', 'string'], 'alamat' => ['nullable', 'string'], 'kk' => ['nullable', 'string'], - 'ktp' => ['nullable', 'string'] + 'ktp' => ['nullable', 'string'], + 'file_kk' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:2048'], + 'file_ktp' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:2048'], + 'desa_kelurahan_id' => ['nullable', 'exists:master_desa_kelurahan,id'], ]); $profile = Profile::where('user_id', Auth::id())->first(); - $profile->update($validated); + + if ($request->hasFile('file_kk')) { + $validated['file_kk'] = $request->file('file_kk')->getClientOriginalName(); + $kkPath = $request->file('file_kk')->store('uploads/profile/' . $profile->id, 'public'); + $validated['path_kk'] = $kkPath; + } + if ($request->hasFile('file_ktp')) { + $validated['file_ktp'] = $request->file('file_ktp')->getClientOriginalName(); + $ktpPath = $request->file('file_ktp')->store('uploads/profile/' . $profile->id, 'public'); + $validated['path_ktp'] = $ktpPath; + } + $validated['updated_by'] = Auth::id(); + + $user = Auth::user(); + + DB::transaction(function () use ($profile, $user, $validated) { + $profile->update($validated); + $user->update([ + 'name' => $validated['nama'], + 'email' => $validated['email'], + 'updated_by' => $user->id, + ]); + }); return response()->json($profile); } @@ -77,4 +107,21 @@ class ProfileController extends Controller { // } + + public function downloadFile(string $id, string $type): JsonResponse | BinaryFileResponse + { + $profile = Profile::where('user_id', Auth::id())->first(); + + if (!$profile) { + return response()->json(['message' => 'Profile tidak ditemukan'], 404); + } + + if ($type === 'kk' && $profile->path_kk) { + return response()->file(storage_path('app/public/' . $profile->path_kk)); + } elseif ($type === 'ktp' && $profile->path_ktp) { + return response()->file(storage_path('app/public/' . $profile->path_ktp)); + } else { + return response()->json(['message' => 'File tidak ditemukan'], 404); + } + } } diff --git a/app/Http/Controllers/Web/KecamatanController.php b/app/Http/Controllers/Web/KecamatanController.php index 9fb15f2..0065a35 100644 --- a/app/Http/Controllers/Web/KecamatanController.php +++ b/app/Http/Controllers/Web/KecamatanController.php @@ -18,10 +18,10 @@ class KecamatanController extends Controller $provinsi = Provinsi::all(); - $kecamatan = Kecamatan::with('kabupatenkota') + $kecamatan = Kecamatan::with('kabupatenKota') ->where('nama', 'like', "%$search%") ->orWhere('kode', 'like', "%$search%") - ->orWhereHas('kabupatenkota', function($query) use ($search) { + ->orWhereHas('kabupatenKota', function($query) use ($search) { $query->where('nama', 'like', "%$search%"); }) ->orderBy('kode', 'asc') diff --git a/app/Http/Resources/ProfileResource.php b/app/Http/Resources/ProfileResource.php new file mode 100644 index 0000000..e64348d --- /dev/null +++ b/app/Http/Resources/ProfileResource.php @@ -0,0 +1,36 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'user_id' => $this->user_id, + 'nama' => $this->nama, + 'email' => $this->email, + 'telepon' => $this->telepon, + 'alamat' => $this->alamat, + 'ktp' => $this->ktp, + 'kk' => $this->kk, + // 'file_ktp' => $this->file_ktp, + // 'file_kk' => $this->file_kk, + 'desa_kelurahan_id' => $this->desa_kelurahan_id, + 'desa_kelurahan' => $this->desaKelurahan ? new DesaKelurahanResource($this->desaKelurahan) : null, + 'user' => $this->user ? new UserResource($this->user) : null, + ]; + } +} diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php new file mode 100644 index 0000000..4af8ec0 --- /dev/null +++ b/app/Http/Resources/UserResource.php @@ -0,0 +1,25 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'email' => $this->email, + 'email_verified_at' => $this->email_verified_at, + 'role' => $this->role, + ]; + } +} diff --git a/app/Http/Resources/Wilayah/DesaKelurahanResource.php b/app/Http/Resources/Wilayah/DesaKelurahanResource.php new file mode 100644 index 0000000..e806145 --- /dev/null +++ b/app/Http/Resources/Wilayah/DesaKelurahanResource.php @@ -0,0 +1,24 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'nama' => $this->nama, + 'kode' => $this->kode, + 'kecamatan' => $this->kecamatan ? new KecamatanResource($this->kecamatan) : null, + ]; + } +} diff --git a/app/Http/Resources/Wilayah/KabupatenKotaResource.php b/app/Http/Resources/Wilayah/KabupatenKotaResource.php new file mode 100644 index 0000000..255d8b1 --- /dev/null +++ b/app/Http/Resources/Wilayah/KabupatenKotaResource.php @@ -0,0 +1,26 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'nama' => $this->nama, + 'kode' => $this->kode, + 'provinsi' => $this->provinsi ? new ProvinsiResource($this->provinsi) : null, + ]; + } +} diff --git a/app/Http/Resources/Wilayah/KecamatanResource.php b/app/Http/Resources/Wilayah/KecamatanResource.php new file mode 100644 index 0000000..adf7412 --- /dev/null +++ b/app/Http/Resources/Wilayah/KecamatanResource.php @@ -0,0 +1,26 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'nama' => $this->nama, + 'kode' => $this->kode, + 'kabupatenKota' => $this->kabupatenKota ? new KabupatenKotaResource($this->kabupatenKota) : null, + ]; + } +} diff --git a/app/Http/Resources/Wilayah/ProvinsiResource.php b/app/Http/Resources/Wilayah/ProvinsiResource.php new file mode 100644 index 0000000..878b004 --- /dev/null +++ b/app/Http/Resources/Wilayah/ProvinsiResource.php @@ -0,0 +1,23 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'nama' => $this->nama, + 'kode' => $this->kode, + ]; + } +} diff --git a/app/Models/Profile.php b/app/Models/Profile.php index 0b36641..f91d3b5 100644 --- a/app/Models/Profile.php +++ b/app/Models/Profile.php @@ -4,8 +4,10 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; -use App\Models\Wilayah\User; + +use App\Models\User; use App\Models\Wilayah\DesaKelurahan; + class Profile extends Model { use SoftDeletes; @@ -31,7 +33,7 @@ class Profile extends Model 'deleted_by' ]; - public function desakelurahan() + public function desaKelurahan() { return $this->belongsTo(DesaKelurahan::class, 'desa_kelurahan_id'); } diff --git a/app/Models/Wilayah/Kecamatan.php b/app/Models/Wilayah/Kecamatan.php index 4631efc..2e287a2 100644 --- a/app/Models/Wilayah/Kecamatan.php +++ b/app/Models/Wilayah/Kecamatan.php @@ -20,11 +20,11 @@ class Kecamatan extends Model 'kabupaten_kota_id', ]; - public function kabupatenkota() { + public function kabupatenKota() { return $this->belongsTo(KabupatenKota::class, 'kabupaten_kota_id'); } - public function desakelurahan() + public function desaKelurahan() { return $this->hasMany(DesaKelurahan::class, 'kecamatan_id'); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 79cc72c..b700b9e 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -8,6 +8,10 @@ use App\Models\User; use App\Enums\Role; use Illuminate\Support\Facades\URL; +use Dedoc\Scramble\Scramble; +use Dedoc\Scramble\Support\Generator\OpenApi; +use Dedoc\Scramble\Support\Generator\SecurityScheme; + class AppServiceProvider extends ServiceProvider { /** @@ -23,6 +27,13 @@ class AppServiceProvider extends ServiceProvider */ public function boot(): void { + Scramble::configure() + ->withDocumentTransformers(function (OpenApi $openApi) { + $openApi->secure( + SecurityScheme::http('bearer') + ); + }); + if (config('app.env') === 'production') { URL::forceScheme('https'); } diff --git a/app/Providers/TelescopeServiceProvider.php b/app/Providers/TelescopeServiceProvider.php new file mode 100644 index 0000000..4de2a6b --- /dev/null +++ b/app/Providers/TelescopeServiceProvider.php @@ -0,0 +1,65 @@ +hideSensitiveRequestDetails(); + + $isLocal = $this->app->environment('local'); + + Telescope::filter(function (IncomingEntry $entry) use ($isLocal) { + return $isLocal || + $entry->isReportableException() || + $entry->isFailedRequest() || + $entry->isFailedJob() || + $entry->isScheduledTask() || + $entry->hasMonitoredTag(); + }); + } + + /** + * Prevent sensitive request details from being logged by Telescope. + */ + protected function hideSensitiveRequestDetails(): void + { + if ($this->app->environment('local')) { + return; + } + + Telescope::hideRequestParameters(['_token']); + + Telescope::hideRequestHeaders([ + 'cookie', + 'x-csrf-token', + 'x-xsrf-token', + ]); + } + + /** + * Register the Telescope gate. + * + * This gate determines who can access Telescope in non-local environments. + */ + protected function gate(): void + { + Gate::define('viewTelescope', function (User $user) { + return in_array($user->email, [ + // + ]); + }); + } +} diff --git a/bootstrap/providers.php b/bootstrap/providers.php index 38b258d..d544739 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -2,4 +2,5 @@ return [ App\Providers\AppServiceProvider::class, + App\Providers\TelescopeServiceProvider::class, ]; diff --git a/composer.json b/composer.json index 3018e7e..98a481f 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,10 @@ "license": "MIT", "require": { "php": "^8.2", + "dedoc/scramble": "^0.13.15", "laravel/framework": "^12.0", "laravel/sanctum": "^4.0", + "laravel/telescope": "^5.18", "laravel/tinker": "^2.10.1" }, "require-dev": { diff --git a/config/scramble.php b/config/scramble.php new file mode 100644 index 0000000..9ab5ad4 --- /dev/null +++ b/config/scramble.php @@ -0,0 +1,136 @@ + 'api', + + /* + * Your API domain. By default, app domain is used. This is also a part of the default API routes + * matcher, so when implementing your own, make sure you use this config if needed. + */ + 'api_domain' => null, + + /* + * The path where your OpenAPI specification will be exported. + */ + 'export_path' => 'api.json', + + 'info' => [ + /* + * API version. + */ + 'version' => env('API_VERSION', '0.0.1'), + + /* + * Description rendered on the home page of the API documentation (`/docs/api`). + */ + 'description' => '', + ], + + /* + * Customize Stoplight Elements UI + */ + 'ui' => [ + /* + * Define the title of the documentation's website. App name is used when this config is `null`. + */ + 'title' => null, + + /* + * Define the theme of the documentation. Available options are `light`, `dark`, and `system`. + */ + 'theme' => 'system', + + /* + * Hide the `Try It` feature. Enabled by default. + */ + 'hide_try_it' => false, + + /* + * Hide the schemas in the Table of Contents. Enabled by default. + */ + 'hide_schemas' => false, + + /* + * URL to an image that displays as a small square logo next to the title, above the table of contents. + */ + 'logo' => '', + + /* + * Use to fetch the credential policy for the Try It feature. Options are: omit, include (default), and same-origin + */ + 'try_it_credentials_policy' => 'include', + + /* + * There are three layouts for Elements: + * - sidebar - (Elements default) Three-column design with a sidebar that can be resized. + * - responsive - Like sidebar, except at small screen sizes it collapses the sidebar into a drawer that can be toggled open. + * - stacked - Everything in a single column, making integrations with existing websites that have their own sidebar or other columns already. + */ + 'layout' => 'responsive', + ], + + /* + * The list of servers of the API. By default, when `null`, server URL will be created from + * `scramble.api_path` and `scramble.api_domain` config variables. When providing an array, you + * will need to specify the local server URL manually (if needed). + * + * Example of non-default config (final URLs are generated using Laravel `url` helper): + * + * ```php + * 'servers' => [ + * 'Live' => 'api', + * 'Prod' => 'https://scramble.dedoc.co/api', + * ], + * ``` + */ + 'servers' => null, + + /** + * Determines how Scramble stores the descriptions of enum cases. + * Available options: + * - 'description' – Case descriptions are stored as the enum schema's description using table formatting. + * - 'extension' – Case descriptions are stored in the `x-enumDescriptions` enum schema extension. + * + * @see https://redocly.com/docs-legacy/api-reference-docs/specification-extensions/x-enum-descriptions + * - false - Case descriptions are ignored. + */ + 'enum_cases_description_strategy' => 'description', + + /** + * Determines how Scramble stores the names of enum cases. + * Available options: + * - 'names' – Case names are stored in the `x-enumNames` enum schema extension. + * - 'varnames' - Case names are stored in the `x-enum-varnames` enum schema extension. + * - false - Case names are not stored. + */ + 'enum_cases_names_strategy' => false, + + /** + * When Scramble encounters deep objects in query parameters, it flattens the parameters so the generated + * OpenAPI document correctly describes the API. Flattening deep query parameters is relevant until + * OpenAPI 3.2 is released and query string structure can be described properly. + * + * For example, this nested validation rule describes the object with `bar` property: + * `['foo.bar' => ['required', 'int']]`. + * + * When `flatten_deep_query_parameters` is `true`, Scramble will document the parameter like so: + * `{"name":"foo[bar]", "schema":{"type":"int"}, "required":true}`. + * + * When `flatten_deep_query_parameters` is `false`, Scramble will document the parameter like so: + * `{"name":"foo", "schema": {"type":"object", "properties":{"bar":{"type": "int"}}, "required": ["bar"]}, "required":true}`. + */ + 'flatten_deep_query_parameters' => true, + + 'middleware' => [ + 'web', + RestrictedDocsAccess::class, + ], + + 'extensions' => [], +]; diff --git a/config/telescope.php b/config/telescope.php new file mode 100644 index 0000000..6250e78 --- /dev/null +++ b/config/telescope.php @@ -0,0 +1,212 @@ + env('TELESCOPE_ENABLED', true), + + /* + |-------------------------------------------------------------------------- + | Telescope Domain + |-------------------------------------------------------------------------- + | + | This is the subdomain where Telescope will be accessible from. If the + | setting is null, Telescope will reside under the same domain as the + | application. Otherwise, this value will be used as the subdomain. + | + */ + + 'domain' => env('TELESCOPE_DOMAIN'), + + /* + |-------------------------------------------------------------------------- + | Telescope Path + |-------------------------------------------------------------------------- + | + | This is the URI path where Telescope will be accessible from. Feel free + | to change this path to anything you like. Note that the URI will not + | affect the paths of its internal API that aren't exposed to users. + | + */ + + 'path' => env('TELESCOPE_PATH', 'telescope'), + + /* + |-------------------------------------------------------------------------- + | Telescope Storage Driver + |-------------------------------------------------------------------------- + | + | This configuration options determines the storage driver that will + | be used to store Telescope's data. In addition, you may set any + | custom options as needed by the particular driver you choose. + | + */ + + 'driver' => env('TELESCOPE_DRIVER', 'database'), + + 'storage' => [ + 'database' => [ + 'connection' => env('DB_CONNECTION', 'mysql'), + 'chunk' => 1000, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Telescope Queue + |-------------------------------------------------------------------------- + | + | This configuration options determines the queue connection and queue + | which will be used to process ProcessPendingUpdate jobs. This can + | be changed if you would prefer to use a non-default connection. + | + */ + + 'queue' => [ + 'connection' => env('TELESCOPE_QUEUE_CONNECTION'), + 'queue' => env('TELESCOPE_QUEUE'), + 'delay' => env('TELESCOPE_QUEUE_DELAY', 10), + ], + + /* + |-------------------------------------------------------------------------- + | Telescope Route Middleware + |-------------------------------------------------------------------------- + | + | These middleware will be assigned to every Telescope route, giving you + | the chance to add your own middleware to this list or change any of + | the existing middleware. Or, you can simply stick with this list. + | + */ + + 'middleware' => [ + 'web', + Authorize::class, + ], + + /* + |-------------------------------------------------------------------------- + | Allowed / Ignored Paths & Commands + |-------------------------------------------------------------------------- + | + | The following array lists the URI paths and Artisan commands that will + | not be watched by Telescope. In addition to this list, some Laravel + | commands, like migrations and queue commands, are always ignored. + | + */ + + 'only_paths' => [ + // 'api/*' + ], + + 'ignore_paths' => [ + 'livewire*', + 'nova-api*', + 'pulse*', + '_boost*', + '.well-known*', + ], + + 'ignore_commands' => [ + // + ], + + /* + |-------------------------------------------------------------------------- + | Telescope Watchers + |-------------------------------------------------------------------------- + | + | The following array lists the "watchers" that will be registered with + | Telescope. The watchers gather the application's profile data when + | a request or task is executed. Feel free to customize this list. + | + */ + + 'watchers' => [ + Watchers\BatchWatcher::class => env('TELESCOPE_BATCH_WATCHER', true), + + Watchers\CacheWatcher::class => [ + 'enabled' => env('TELESCOPE_CACHE_WATCHER', true), + 'hidden' => [], + 'ignore' => [], + ], + + Watchers\ClientRequestWatcher::class => [ + 'enabled' => env('TELESCOPE_CLIENT_REQUEST_WATCHER', true), + 'ignore_hosts' => [], + ], + + Watchers\CommandWatcher::class => [ + 'enabled' => env('TELESCOPE_COMMAND_WATCHER', true), + 'ignore' => [], + ], + + Watchers\DumpWatcher::class => [ + 'enabled' => env('TELESCOPE_DUMP_WATCHER', true), + 'always' => env('TELESCOPE_DUMP_WATCHER_ALWAYS', false), + ], + + Watchers\EventWatcher::class => [ + 'enabled' => env('TELESCOPE_EVENT_WATCHER', true), + 'ignore' => [], + ], + + Watchers\ExceptionWatcher::class => env('TELESCOPE_EXCEPTION_WATCHER', true), + + Watchers\GateWatcher::class => [ + 'enabled' => env('TELESCOPE_GATE_WATCHER', true), + 'ignore_abilities' => [], + 'ignore_packages' => true, + 'ignore_paths' => [], + ], + + Watchers\JobWatcher::class => env('TELESCOPE_JOB_WATCHER', true), + + Watchers\LogWatcher::class => [ + 'enabled' => env('TELESCOPE_LOG_WATCHER', true), + 'level' => 'error', + ], + + Watchers\MailWatcher::class => env('TELESCOPE_MAIL_WATCHER', true), + + Watchers\ModelWatcher::class => [ + 'enabled' => env('TELESCOPE_MODEL_WATCHER', true), + 'events' => ['eloquent.*'], + 'hydrations' => true, + ], + + Watchers\NotificationWatcher::class => env('TELESCOPE_NOTIFICATION_WATCHER', true), + + Watchers\QueryWatcher::class => [ + 'enabled' => env('TELESCOPE_QUERY_WATCHER', true), + 'ignore_packages' => true, + 'ignore_paths' => [], + 'slow' => 100, + ], + + Watchers\RedisWatcher::class => env('TELESCOPE_REDIS_WATCHER', true), + + Watchers\RequestWatcher::class => [ + 'enabled' => env('TELESCOPE_REQUEST_WATCHER', true), + 'size_limit' => env('TELESCOPE_RESPONSE_SIZE_LIMIT', 64), + 'ignore_http_methods' => [], + 'ignore_status_codes' => [], + ], + + Watchers\ScheduleWatcher::class => env('TELESCOPE_SCHEDULE_WATCHER', true), + Watchers\ViewWatcher::class => env('TELESCOPE_VIEW_WATCHER', true), + ], +]; diff --git a/database/migrations/2026_03_16_221143_create_telescope_entries_table.php b/database/migrations/2026_03_16_221143_create_telescope_entries_table.php new file mode 100644 index 0000000..031b6f4 --- /dev/null +++ b/database/migrations/2026_03_16_221143_create_telescope_entries_table.php @@ -0,0 +1,70 @@ +getConnection()); + + $schema->create('telescope_entries', function (Blueprint $table) { + $table->bigIncrements('sequence'); + $table->uuid('uuid'); + $table->uuid('batch_id'); + $table->string('family_hash')->nullable(); + $table->boolean('should_display_on_index')->default(true); + $table->string('type', 20); + $table->longText('content'); + $table->dateTime('created_at')->nullable(); + + $table->unique('uuid'); + $table->index('batch_id'); + $table->index('family_hash'); + $table->index('created_at'); + $table->index(['type', 'should_display_on_index']); + }); + + $schema->create('telescope_entries_tags', function (Blueprint $table) { + $table->uuid('entry_uuid'); + $table->string('tag'); + + $table->primary(['entry_uuid', 'tag']); + $table->index('tag'); + + $table->foreign('entry_uuid') + ->references('uuid') + ->on('telescope_entries') + ->cascadeOnDelete(); + }); + + $schema->create('telescope_monitoring', function (Blueprint $table) { + $table->string('tag')->primary(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + $schema = Schema::connection($this->getConnection()); + + $schema->dropIfExists('telescope_entries_tags'); + $schema->dropIfExists('telescope_entries'); + $schema->dropIfExists('telescope_monitoring'); + } +}; diff --git a/routes/api.php b/routes/api.php index de015c7..fa2da70 100644 --- a/routes/api.php +++ b/routes/api.php @@ -18,8 +18,10 @@ Route::middleware('auth:sanctum') Route::get('/me', [\App\Http\Controllers\Api\AuthController::class, 'me']); Route::post('/logout', [\App\Http\Controllers\Api\AuthController::class, 'logout']); - Route::get('/profile', [\App\Http\Controllers\Api\ProfileController::class, 'show']); - Route::put('/profile/{id}', [\App\Http\Controllers\Api\ProfileController::class, 'update']); + // Route::get('/profile', [\App\Http\Controllers\Api\ProfileController::class, 'show']); + // Route::put('/profile/{id}', [\App\Http\Controllers\Api\ProfileController::class, 'update']); + Route::get('/profile/{id}/download/{type}', [\App\Http\Controllers\Api\ProfileController::class, 'downloadFile']); + Route::apiResource('/profile', \App\Http\Controllers\Api\ProfileController::class)->only(['show', 'update']); }); Route::middleware('auth:sanctum')