Reputation: 75
i am getting value of wallet
and refer
from form with $request->wallet
and $request->refer
i am getting only the value of wallet not refer route is a POST route
. i have also added csrf but not working
code for controller
$acc['wallet'] = $request->wallet;
$acc['balance'] = 0;
$acc['uqid'] = rand(10000000,99999999);
$acc['ref'] = $request->refer;
$ck = Account::where('uqid', $acc['uqid'])->first();
if(isset($ck))
{
$acc['uqid'] = rand(10000000,99999999);
}
Account::create($acc);
View:
@if(session('CurrentAccount')=='')
<form id="checkForm">
@csrf
<input type="text" class="wallet-input" name="wallet" placeholder="Your Address...">
<input type="text" class="wallet-input" name="refer" value="{{ app('request')->input('ref') }}">
<button type="submit">Enter</button>
</form>
@endif
Ajax:
$(document).on('submit','#checkForm',function(event)
{
event.preventDefault();
$.ajax({
type:"POST",
url:"{{route('account.check')}}",
data: new FormData(document.getElementById('checkForm')),
contentType: false,
processData: false,
success:function(data)
{
console.log(data)
if(data==99)
{
$.notify({ allow_dismiss: true,title: "Sorry!",message: "Invalid" }, { type: 'danger' });
}
Upvotes: 0
Views: 829
Reputation: 9055
It seems like your value
attribute id not getting a proper value from request.
Specifically check if {{ app('request')->input('ref') }}
is getting any value in :
<input type="text" class="wallet-input" name="refer" value="{{ app('request')->input('ref') }}">
Secondly inside controller :
$account = Account::create([
'wallet' = $request->input('wallet'),
'balance' = 0,
'uqid' = rand(10000000,99999999),
'ref' = $request->input('refer'),
'uqid' = Account::where('uqid', $acc['uqid'])->exists() ? rand(10000000,99999999) : null
]);
(assuming you have these columns in $fillable =[]
array in Account
model)
Check into network tab of your browser to see what data you are posting. If there is no value for input then controller will not get anything.
Upvotes: 1
Reputation: 119
When you need to create uuid, use a helper function you got in laravel Str::uuid(), and you don't need to query your db to make sure it didn't exist before.
especially that it can still be duplicated with the code you have now.
and you didn't define the new account object.
$acc = new App\Account;
$acc->wallet = $request->wallet;
$acc->balance = 0;
$acc->uqid = Str::uuid();
$acc->ref = $request->refer;
$acc->save();
and the form method and action are not defined:
@if(session('CurrentAccount')=='')
<form id="checkForm" action="{{ route('method/route') }}" method="POST">
@csrf
<input type="text" class="wallet-input" name="wallet" placeholder="Your Address...">
<input type="text" class="wallet-input" name="refer" value="{{ app('request')->input('ref') }}">
<button type="submit">Enter</button>
</form>
@endif
Upvotes: 0
Reputation: 1981
Instead of
$request->wallet;
$request->refer;
changes to
$request->get('wallet');
$request->get('refer');
Upvotes: 0