I want to pass two variables from the form in the view to my controller and there to use them... But I don't know how...
Can you help me?
shop.blade.php:
<div class="mcitem">
<img src="/images/shop/Stein.png" alt="Stein">
<div class="mcunits">
</div>
<div class="mcbuy">
$itemid = 1;
$bprice = 3;
</div>
<div class="mcsell">
</div>
</div>
ShopController:
public function add(Request $request){
$this->validate($request, [
'units' => 'required|min:1',
]);
if(Input::Get('buybtn')) {
$this->Buy(); //if Buy Button is pushed
} elseif(Input::Get('sellbtn')) {
$this->Sell(); //if Sell Button is pushed
}
}
public function Buy(){
$username = Auth::user()->name;
$units = Input::Get('units');
if((DB::table('users')->where('name', $username)->value('kontostand')) >= ($bprice*$units)){
$check_entry = DB::table($username)->where('Item', '=', $itemid)->first();
if(is_null($check_entry)){
$hunits = DB::table($username)->where('Item', $itemid)->select('units')->get();
DB::table($username)->where('Item', $itemid)->update([$itemid => $hunits + $units]);
}
else{
DB::table($username)->where('Item', $itemid)->insert(
[$itemid => $units]
);
}
}
else{
echo "Zu wenig Geld auf dem Kontostand!";
}
}
I know now it's completly wrong because I tried so much but yeah...Nothing happens...
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire