Fix with Deposit controller endpoint

This commit is contained in:
Anna-Sara Sélea 2025-05-05 19:39:43 +02:00
parent a457a4615b
commit d9f15a2d99
4 changed files with 19 additions and 9 deletions

View file

@ -28,23 +28,24 @@ class DepositController extends Controller
/**
* Store a newly created resource in storage.
*/
public function store(Request $request, $id)
public function store(Request $request)
{
$request->validate([
'customer_id' => 'required',
'deposit' => 'required',
]);
Deposit::create([
'customer_id' => $id,
'customer_id' => $request->customer_id,
'amount' => $request->deposit,
]);
$customer = Customer::findOrFail($id);
$customer = Customer::findOrFail($request->customer_id);
$customer->deposit = $customer->deposit + $request->deposit;
$customer->amount_left = $customer->amount_left + $request->deposit;
$customer->save();
return redirect('customer/' . $customer->id);
return redirect('customer/' . $request->customer_id);
}
/**

View file

@ -1,15 +1,25 @@
@import 'bulma/css/bulma.min.css';
:root {
--button-link-background-color: #0080bb;
--button-link-color: #fff;
}
.button {
background-color: var(--button-link-background-color);
color: var(--button-link-color);
}
.button.letter {
background-color: #fff;
color: #000;
border: 1px solid lightgray;
}
.is-active.letter {
background-color: var(--button-link-background-color);
color: var(--button-link-color);
}
.navbar-logo {

View file

@ -29,7 +29,6 @@ export default function Customer({customer}: CustomerProps) {
customer_id: customer.id,
deposit: "",
id: customer.id
});
const submit: FormEventHandler = (e) => {
@ -41,7 +40,7 @@ export default function Customer({customer}: CustomerProps) {
const submitDeposit: FormEventHandler = (e) => {
e.preventDefault()
post('/api/register_deposit/' + customer.id, {
post(route('register_deposit'), {
onFinish: () => reset('deposit'),
});
}

View file

@ -9,6 +9,6 @@ use App\Http\Controllers\DepositController;
Route::post('register_customer', [CustomerController::class, 'store'])->name('register_customer');
Route::middleware('auth:sanctum')->group(function () {
Route::post('register_deposit/{id}', [DepositController::class, 'store']);
Route::post('register_deposit', [DepositController::class, 'store'])->name('register_deposit');
Route::post('register_purchase', [PurchaseController::class, 'store'])->name('register_purchase');
});