enkf

Untitled

Jan 29th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Api;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. use App\Models\Booking;
  8. use Auth;
  9. use Carbon;
  10.  
  11. class BookingController extends Controller
  12. {
  13. public function index()
  14. {
  15. $member = Auth::guard('member-api')->user();
  16. $bookings = Booking::orderBy('id','DESC', $member->id)->paginate(5);
  17.  
  18. return response()->json([
  19. 'success' => true,
  20. 'message' => 'Get Booking',
  21. 'results' => [
  22. 'bookings' => $bookings,
  23. ]
  24. ], 200);
  25. }
  26.  
  27. public function store(Request $request)
  28. {
  29. $this->validate($request, [
  30. 'date' => 'required',
  31. 'time' => 'required'
  32. ]);
  33.  
  34. $attributes = ([
  35. 'member_id' => $member_id,
  36. 'date' => date("Y-m-d", strtotime(str_replace("/", "-", $request->date))),
  37. 'time' => Carbon::now()
  38. ]);
  39.  
  40. $bookings = Booking::create($attributes);
  41. return response()->json([
  42. 'success' => true,
  43. 'message' => 'Add Booking Successfully',
  44. 'results' => [
  45. 'bookings' => $bookings
  46. ]
  47. ], 200);
  48.  
  49. }
  50.  
  51.  
  52.  
  53.  
  54. }
Add Comment
Please, Sign In to add comment