From 392fca86350dc03a8063a825d471b6dd05c185f1 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 1 Jun 2026 15:26:09 +0330 Subject: [PATCH] add three column in user_gateways and use them in controller --- .../GatewayManagementController.php | 31 ++++++++++++++----- ...ent_credentials_to_user_gateways_table.php | 30 ++++++++++++++++++ 2 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 backend/database/migrations/2026_06_01_102551_add_client_credentials_to_user_gateways_table.php diff --git a/backend/app/User/Controllers/GatewayManagementController.php b/backend/app/User/Controllers/GatewayManagementController.php index 690d364e..51fa183a 100644 --- a/backend/app/User/Controllers/GatewayManagementController.php +++ b/backend/app/User/Controllers/GatewayManagementController.php @@ -14,6 +14,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; +use Laravel\Passport\ClientRepository; use Throwable; class GatewayManagementController extends Controller @@ -27,7 +28,8 @@ class GatewayManagementController extends Controller $request, allowedFilters: ['*'], allowedSortings: ['*'], - allowedSelects: ['id', 'name', 'domain', 'tax_id', 'bank_name', 'account_holder', 'iban', 'business_type_id', 'business_type_name'], + allowedSelects: ['id', 'name', 'domain', 'tax_id', 'bank_name', 'account_holder', 'iban', + 'business_type_id', 'business_type_name','created_at', 'status'], ); } @@ -38,10 +40,15 @@ class GatewayManagementController extends Controller { $user = Auth::guard('web')->user(); - $logo = $request->has('logo') ? FileFacade::save($request->file('logo'), "{$user->id}") : null; + $logo = $request->hasFile('logo') + ? FileFacade::save($request->file('logo'), "{$user->id}") + : null; - DB::transaction(function () use ($user, $logo, $request) { - UserGateway::query()->create([ + $result = DB::transaction(function () use ($user, $logo, $request) { + $client = app(ClientRepository::class) + ->createClientCredentialsGrantClient($request->name); + + $gateway = UserGateway::query()->create([ 'user_id' => $user->id, 'username' => $user->username, 'name' => $request->name, @@ -53,15 +60,25 @@ class GatewayManagementController extends Controller 'business_type_id' => $request->business_type_id, 'business_type_name' => BusinessTypeEnum::name($request->business_type_id), 'logo' => $logo, + + // save Passport client info in your own table + 'client_id' => $client->id, + 'client_secret' => $client->secret, ]); $user->update(['authority_level' => 1]); + + return [ + 'gateway' => $gateway, + 'client' => $client, + ]; }); - - return $this->successResponse(); + return $this->successResponse([ + 'client_id' => $result['client']->id, + 'client_secret' => $result['client']->secret, + ]); } - public function show(UserGateway $gateway): JsonResponse { return $this->successResponse($gateway); diff --git a/backend/database/migrations/2026_06_01_102551_add_client_credentials_to_user_gateways_table.php b/backend/database/migrations/2026_06_01_102551_add_client_credentials_to_user_gateways_table.php new file mode 100644 index 00000000..29c56dce --- /dev/null +++ b/backend/database/migrations/2026_06_01_102551_add_client_credentials_to_user_gateways_table.php @@ -0,0 +1,30 @@ +string('client_id')->unique()->nullable(); + $table->string('client_secret')->nullable(); + $table->integer('status')->default(0); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('user_gateways', function (Blueprint $table) { + $table->dropColumn('client_id', 'client_secret','status'); + }); + } +};