Reputation: 57
Good day, I have an issue with my codes here. I'll be more explicit.
The pro problem is when I try to access the amount with $request->amount. I m getting "null
".
CONTROLLER THAT SENDS THE EMAIL TO THE ADMIN TO APPROVE
public function sendApproveReplenishEmail(Request $request) {
//$IP_PORT =$_SERVER['REMOTE_ADDR'].":".$_SERVER['REMOTE_PORT'];
$IP =$_SERVER['REMOTE_ADDR'];
//pass the userId of the person you want to activate
// $user_id =Auth::user()->id;
//Create id
$id = $request->id;
//Create token
$token = (string) Str::uuid();
//save token in DB
$result = User::where('id', $id)
->update(['notify_token' => $token]);
if($result != 1){ //let us return if we cannot update
return nl2br ("\n We could not save token");
}
$activationUrl = 'http://'.$IP.':8001/admin/approve-replenish/'.$token;
$details =[
'title' => 'Please approve replenish by clicking the link below:',
'body' => $activationUrl
];
Mail::to('[email protected]')->send(new ApproveReplenishMail($details));
return nl2br ("\nReplenish approval Email sent");
}
THE CONTROLLER THAT SAVES THE DATA TO THE DATABASE - [the admin calls this controller after clicking the provided link]
try{
$tokenid =$request->token;
$user = User::select('name','id')->where('notify_token', $tokenid)->first();
//model User should not be empty
if(is_null($user)) {
return nl2br ("\nUser with token .$tokenid. not found");
}
// $userId =$user->id;
// $userId = User::select('id')->where('notify_token', $tokenid)->first();
// echo nl2br ("\n$userId");
$userId = $user->id;
$float = Balance::where('user_id',$userId)->first();
//model Balance should not be empty
if(is_null($float)) {
return nl2br ("Record with id .$userId. not found");
}else{
if($float->float > 0){
$float->float = $float->float + $request->amount;
}else{
$float->float=$request->amount;
}
$float->user_id=$userId;
$float->save();
$request->session()->flash('success', 'You have successfully updated the client float');
//we can delete token if necessary
$user->update(['notify_token' => null]);
}
}catch (Exception $e) {
echo $e;
}
return redirect(url('admin/float/floats'));
}```
WEB.PHP ROUTES FOR THOSE CONTROLLERS
```Route::get('/approve-replenish/{token}', [ReplenishController::class,'approveReplenish'])->name('approve-replenish');
Route::get('/send-replenish-mail/{id}', [ReplenishController::class,'sendApproveReplenishEmail'])->name('send-replenish-mail');
WHAT I HAVE DONE SO FAR.
I was suspecting the GET Method since I m submitting the form, but unfortunately when I change GET to POST I get an error message saying GET is not supported... NB[I change from the blade file and routes].
MAIN ISSUE: I m not able to access the $request->amount
in order to save it.
Upvotes: 0
Views: 796
Reputation: 913
Add amount to your route
just the way I added in this one below,
Route::get('/approve-replenish/{token}/{amount}
then wherever you are calling this URL you're supposed to pass the amount right after the token, check the code below, and modify it accordingly in your public function sendApproveReplenishEmail(Request $request)
$activationUrl = 'http://'.$IP.':8001/admin/approve-replenish/'.$token.'/'.$youramount;
Upvotes: 1