PostsController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Foundation\Auth;
  5. use App\Services\moneyService;
  6. use Illuminate\Support\Facades\Validator;
  7. class PostsController extends Controller
  8. {
  9. public function index(Request $request)
  10. {
  11. $validatedData = $request->validate([
  12. 'email' => 'required|email',
  13. 'num' => 'required|numeric'
  14. ]);
  15. session()->flash('status', 'Thanks for funding your acc!');
  16. if (auth()->check()) {
  17. $bank= new \App\bank;
  18. $vs=$bank::where('user_id', auth()->user()->id)->count();
  19. if($vs==0){
  20. $bank->user_id=auth()->user()->id;
  21. $bank->money=$request->num;
  22. $bank->email=$request->email;
  23. $bank->save();
  24. }
  25. else{
  26. $mon=$request->num;
  27. $cal=\App\bank::where('user_id', auth()->user()->id)->get('money');
  28. $res = json_decode($cal, true);
  29. $upd=$res[0]['money'];
  30. $bank::where('user_id', auth()->user()->id)->update(['money' => $upd+$mon]);
  31. }
  32. }
  33. return view('posts.index');
  34. }
  35. public function indexx(){
  36. return view('posts.index');
  37. }
  38. public function daily()
  39. {
  40. return view('posts.daily');
  41. }
  42. public function casino(){
  43. return view('posts.casino');
  44. }
  45. public function post_casino(Request $request){
  46. $validator = Validator::make($request->all(), [
  47. 'num' => 'required|numeric'
  48. ]);
  49. if ($validator->fails()) {
  50. return redirect('casino')
  51. ->withErrors($validator)
  52. ->withInput();
  53. }
  54. $mon = $request->num;
  55. $cal=\App\bank::where('user_id', auth()->user()->id)->get('money');
  56. $res = json_decode($cal, true);
  57. $upd=$res[0]['money'];
  58. if($mon>$upd){
  59. echo "You dont have enough money!";
  60. $validator->errors()->add('num', 'You dont have enough money!');
  61. }
  62. else{
  63. $bank= new \App\bank;
  64. $bank::where('user_id', auth()->user()->id)->update(['money' => $upd-$mon]);
  65. $mS=new moneyService;
  66. $newmon=$mS->multiply2($mon);
  67. $bank::where('user_id', auth()->user()->id)->update(['money' => $upd-$mon+$newmon]);
  68. return view('posts.casino',
  69. ['mon'=>$mon,
  70. 'newmon'=>$newmon]);
  71. }
  72. }
  73. }