Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers\Api;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use App\Models\Booking;
- use Auth;
- use Carbon;
- class BookingController extends Controller
- {
- public function index()
- {
- $member = Auth::guard('member-api')->user();
- $bookings = Booking::orderBy('id','DESC', $member->id)->paginate(5);
- return response()->json([
- 'success' => true,
- 'message' => 'Get Booking',
- 'results' => [
- 'bookings' => $bookings,
- ]
- ], 200);
- }
- public function store(Request $request)
- {
- $this->validate($request, [
- 'date' => 'required',
- 'time' => 'required'
- ]);
- $attributes = ([
- 'member_id' => $member_id,
- 'date' => date("Y-m-d", strtotime(str_replace("/", "-", $request->date))),
- 'time' => Carbon::now()
- ]);
- $bookings = Booking::create($attributes);
- return response()->json([
- 'success' => true,
- 'message' => 'Add Booking Successfully',
- 'results' => [
- 'bookings' => $bookings
- ]
- ], 200);
- }
- }
Add Comment
Please, Sign In to add comment