⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.81
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
Server Software:
Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.25
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
ecommerce.dev-unit.com
/
routes
/
View File Name :
api.php
<?php use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; use App\Http\Controllers\Api\AuthController; use App\Http\Controllers\Api\UserController; use App\Http\Controllers\Api\ProductController; use App\Http\Controllers\Api\CategoryController; use App\Http\Controllers\Api\CartController; use App\Http\Controllers\Api\WishlistController; use App\Http\Controllers\Api\OrderController; /* |-------------------------------------------------------------------------- | API Routes |-------------------------------------------------------------------------- | | Here is where you can register API routes for your application. These | routes are loaded by the RouteServiceProvider and all of them will | be assigned to the "api" middleware group. Make something great! | */ Route::prefix('v1')->group(function () { // Public authentication routes Route::prefix('auth')->group(function () { // Register new user Route::post('register', [AuthController::class, 'register']) ->name('api.auth.register'); // Login user Route::post('login', [AuthController::class, 'login']) ->name('api.auth.login'); // Send password reset link Route::post('forgot-password', [AuthController::class, 'forgotPassword']) ->name('api.auth.forgot-password'); // Reset password Route::post('reset-password/{token}', [AuthController::class, 'resetPassword']) ->name('api.auth.reset-password'); // Verify email Route::get('verify/{token}', [AuthController::class, 'verifyEmail']) ->name('api.auth.verify'); // Resend verification email Route::post('resend-verification', [AuthController::class, 'resendVerification']) ->name('api.auth.resend-verification'); }); // Public product routes (no authentication required) Route::prefix('products')->group(function () { // Get all products with filters and pagination Route::get('/', [ProductController::class, 'index']) ->name('api.products.index'); // Get featured products Route::get('/featured', [ProductController::class, 'featured']) ->name('api.products.featured'); // Get latest products Route::get('/latest', [ProductController::class, 'latest']) ->name('api.products.latest'); // Search products Route::get('/search', [ProductController::class, 'search']) ->name('api.products.search'); // Get a single product by ID or slug (must come last) Route::get('/{identifier}', [ProductController::class, 'show']) ->name('api.products.show'); }); // Public category routes (no authentication required) Route::prefix('categories')->group(function () { // Get all categories Route::get('/', [CategoryController::class, 'index']) ->name('api.categories.index'); // Get single category Route::get('/{identifier}', [CategoryController::class, 'show']) ->name('api.categories.show'); // Get subcategories Route::get('/{categoryId}/subcategories', [CategoryController::class, 'getSubcategories']) ->name('api.categories.subcategories'); // Get childcategories Route::get('/subcategories/{subcategoryId}/childcategories', [CategoryController::class, 'getChildcategories']) ->name('api.categories.childcategories'); // Get products by category Route::get('/{id}/products', [ProductController::class, 'getByCategory']) ->name('api.categories.products'); }); // Public brand routes (no authentication required) Route::prefix('brands')->group(function () { // Get products by brand Route::get('/{id}/products', [ProductController::class, 'getByBrand']) ->name('api.brands.products'); }); // Public cart routes (no authentication required - uses session) Route::prefix('cart')->group(function () { // Get cart contents Route::get('/', [CartController::class, 'index']) ->name('api.cart.index'); // Get cart count Route::get('/count', [CartController::class, 'count']) ->name('api.cart.count'); // Add item to cart Route::post('/add', [CartController::class, 'add']) ->name('api.cart.add'); // Update cart item Route::post('/update', [CartController::class, 'update']) ->name('api.cart.update'); // Remove item from cart Route::post('/remove', [CartController::class, 'remove']) ->name('api.cart.remove'); // Clear cart Route::post('/clear', [CartController::class, 'clear']) ->name('api.cart.clear'); }); // Protected authentication routes (require authentication) Route::middleware('auth:sanctum')->prefix('auth')->group(function () { // Get authenticated user Route::get('me', [AuthController::class, 'me']) ->name('api.auth.me'); // Refresh token Route::post('refresh', [AuthController::class, 'refresh']) ->name('api.auth.refresh'); // Logout user Route::post('logout', [AuthController::class, 'logout']) ->name('api.auth.logout'); }); // Protected user routes (require authentication) Route::middleware('auth:sanctum')->group(function () { // Get authenticated user profile Route::get('user', [UserController::class, 'getProfile']) ->name('api.user.profile'); // Update authenticated user profile Route::post('update-profile', [UserController::class, 'updateProfile']) ->name('api.user.update'); // Get countries Route::get('get-countries', [UserController::class, 'getCountries']) ->name('api.user.countries'); // Update authenticated user billing address Route::post('update-billing-address', [UserController::class, 'updateBillingAddress']) ->name('api.user.update-billing-address'); // Update authenticated user shipping address Route::post('update-shipping-address', [UserController::class, 'updateShippingAddress']) ->name('api.user.update-shipping-address'); }); // Protected wishlist routes (require authentication) Route::middleware('auth:sanctum')->prefix('wishlist')->group(function () { // Get user wishlist Route::get('/', [WishlistController::class, 'index']) ->name('api.wishlist.index'); // Add product to wishlist Route::post('/add', [WishlistController::class, 'add']) ->name('api.wishlist.add'); // Remove product from wishlist Route::post('/remove', [WishlistController::class, 'remove']) ->name('api.wishlist.remove'); // Check if product in wishlist Route::get('/check/{productId}', [WishlistController::class, 'check']) ->name('api.wishlist.check'); // Clear wishlist Route::post('/clear', [WishlistController::class, 'clear']) ->name('api.wishlist.clear'); }); // Protected order routes (require authentication) Route::middleware('auth:sanctum')->prefix('orders')->group(function () { // Get user orders Route::get('/', [OrderController::class, 'index']) ->name('api.orders.index'); // Create new order Route::post('/store', [OrderController::class, 'store']) ->name('api.orders.store'); // Get single order Route::get('/{orderId}', [OrderController::class, 'show']) ->name('api.orders.show'); // Track order Route::get('/{orderId}/track', [OrderController::class, 'track']) ->name('api.orders.track'); // Cancel order Route::post('/{orderId}/cancel', [OrderController::class, 'cancel']) ->name('api.orders.cancel'); }); }); // Health check endpoint Route::get('health', function () { return response()->json([ 'status' => 'ok', 'message' => 'API is running', 'timestamp' => now()->toIso8601String() ]); })->name('api.health');