|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Http\Controllers\User; |
| 4 | + |
| 5 | +use App\Models\Camp; |
| 6 | +use App\Models\Checkout; |
| 7 | +use Illuminate\Http\Request; |
| 8 | +use App\Http\Controllers\Controller; |
| 9 | +use Auth; |
| 10 | + |
| 11 | +class CheckoutController extends Controller |
| 12 | +{ |
| 13 | + /** |
| 14 | + * Display a listing of the resource. |
| 15 | + * |
| 16 | + * @return \Illuminate\Http\Response |
| 17 | + */ |
| 18 | + public function index() |
| 19 | + { |
| 20 | + // |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Show the form for creating a new resource. |
| 25 | + * |
| 26 | + * @return \Illuminate\Http\Response |
| 27 | + */ |
| 28 | + public function create(Camp $camp) |
| 29 | + { |
| 30 | + return view('checkout.create',[ |
| 31 | + 'camp' => $camp |
| 32 | + ]); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Store a newly created resource in storage. |
| 37 | + * |
| 38 | + * @param \Illuminate\Http\Request $request |
| 39 | + * @return \Illuminate\Http\Response |
| 40 | + */ |
| 41 | + public function store(Request $request, Camp $camp) |
| 42 | + { |
| 43 | + // mapping request data |
| 44 | + $data = $request->all(); |
| 45 | + $data['user_id'] = Auth::id(); |
| 46 | + $data['camp_id'] = $camp->id; |
| 47 | + |
| 48 | + // Update user data |
| 49 | + $user = Auth::user(); |
| 50 | + $user->email = $data['email']; |
| 51 | + $user->name = $data['name']; |
| 52 | + $user->occupation = $data['occupation']; |
| 53 | + $user->save(); |
| 54 | + |
| 55 | + // create checkout |
| 56 | + $checkout = Checkout::create($data); |
| 57 | + |
| 58 | + return redirect(route('checkout.success')); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Display the specified resource. |
| 63 | + * |
| 64 | + * @param \App\Models\Checkout $checkout |
| 65 | + * @return \Illuminate\Http\Response |
| 66 | + */ |
| 67 | + public function show(Checkout $checkout) |
| 68 | + { |
| 69 | + // |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Show the form for editing the specified resource. |
| 74 | + * |
| 75 | + * @param \App\Models\Checkout $checkout |
| 76 | + * @return \Illuminate\Http\Response |
| 77 | + */ |
| 78 | + public function edit(Checkout $checkout) |
| 79 | + { |
| 80 | + // |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Update the specified resource in storage. |
| 85 | + * |
| 86 | + * @param \Illuminate\Http\Request $request |
| 87 | + * @param \App\Models\Checkout $checkout |
| 88 | + * @return \Illuminate\Http\Response |
| 89 | + */ |
| 90 | + public function update(Request $request, Checkout $checkout) |
| 91 | + { |
| 92 | + // |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Remove the specified resource from storage. |
| 97 | + * |
| 98 | + * @param \App\Models\Checkout $checkout |
| 99 | + * @return \Illuminate\Http\Response |
| 100 | + */ |
| 101 | + public function destroy(Checkout $checkout) |
| 102 | + { |
| 103 | + // |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Remove the specified resource from storage. |
| 108 | + * |
| 109 | + * @param \App\Models\Checkout $checkout |
| 110 | + * @return \Illuminate\Http\Response |
| 111 | + */ |
| 112 | + public function success(Checkout $checkout) |
| 113 | + { |
| 114 | + return view('checkout.success'); |
| 115 | + } |
| 116 | +} |
0 commit comments