feat: add withdraw request functionality and UI components
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Client\InvoiceResource;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\Wallet\WalletService;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
protected WalletService $walletService;
|
||||
|
||||
public function __construct(WalletService $walletService)
|
||||
{
|
||||
$this->walletService = $walletService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$invoices = Auth::user()->invoices()
|
||||
->with('document')
|
||||
->latest()
|
||||
->paginate(10)
|
||||
->withQueryString()
|
||||
->onEachSide(1);
|
||||
|
||||
return Inertia::client('Dashboard/Invoices/Index', [
|
||||
'invoices' => InvoiceResource::collection($invoices),
|
||||
]);
|
||||
}
|
||||
|
||||
public function payWithWallet(Invoice $invoice)
|
||||
{
|
||||
abort_unless($invoice->user_id === Auth::id(), 403);
|
||||
|
||||
$invoice = $this->walletService->payInvoice(Auth::user(), $invoice);
|
||||
|
||||
return response()->json([
|
||||
'invoice' => new InvoiceResource($invoice),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user