Viewing file: TourController.php (3.15 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Customer;
use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth;
class TourController extends Controller { /** * Mark the tour as completed for the authenticated customer * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function markCompleted(Request $request) { try { $customer = Auth::guard('customer')->user(); if (!$customer) { return response()->json([ 'status' => 'error', 'message' => 'User not authenticated' ], 401); }
$customer->tour_completed = true; $customer->tour_last_seen = now(); $customer->save();
return response()->json([ 'status' => 'success', 'message' => 'Tour marked as completed' ]); } catch (\Exception $e) { return response()->json([ 'status' => 'error', 'message' => 'Failed to mark tour as completed: ' . $e->getMessage() ], 500); } }
/** * Reset the tour for the authenticated customer * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function resetTour(Request $request) { try { $customer = Auth::guard('customer')->user(); if (!$customer) { return response()->json([ 'status' => 'error', 'message' => 'User not authenticated' ], 401); }
$customer->tour_completed = false; $customer->tour_last_seen = now(); $customer->save();
return response()->json([ 'status' => 'success', 'message' => 'Tour has been reset' ]); } catch (\Exception $e) { return response()->json([ 'status' => 'error', 'message' => 'Failed to reset tour: ' . $e->getMessage() ], 500); } }
/** * Get the tour status for the authenticated customer * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function getTourStatus(Request $request) { try { $customer = Auth::guard('customer')->user(); if (!$customer) { return response()->json([ 'status' => 'error', 'message' => 'User not authenticated' ], 401); }
return response()->json([ 'status' => 'success', 'data' => [ 'tour_completed' => (bool) $customer->tour_completed, 'tour_last_seen' => $customer->tour_last_seen ] ]); } catch (\Exception $e) { return response()->json([ 'status' => 'error', 'message' => 'Failed to get tour status: ' . $e->getMessage() ], 500); } } }
|