add three column in user_gateways and use them in controller
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('user_gateways', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user