laravel-api / routes / api.php
api.php
Raw
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\ItemController;
use App\Http\Controllers\AuthController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

/*-----Route for registration and login --------*/
Route::post('/register',[AuthController::class, 'register']);
Route::post('/login',[AuthController::class, 'login']);
Route::post('/logout',[AuthController::class, 'logout'])->middleware('auth:sanctum');
Route::get('/user',[AuthController::class, 'getUser']);


/*-----Routes for category--------*/

// Get All categories 
Route::get('/category',[CategoryController::class,'getCategory'])->middleware('auth:sanctum'); 
// Post a category
Route::post('/addcategory',[CategoryController::class,'addCategory'])->middleware('auth:sanctum'); 


/*-----Routes for item--------*/

// Get all items
Route::get('/item',[ItemController::class, 'showAllItems'])->middleware('auth:sanctum');
// Post item and sending category id 
Route::post('/additem/{id}',[ItemController::class, 'addItem'])->middleware('auth:sanctum');
// Delete an item 
Route::delete('/item/{id}',[ItemController::class, 'deleteItem'])->middleware('auth:sanctum');
// Get an item by its id 
Route::get('item/{id}',[ItemController::class, 'getItemById'])->middleware('auth:sanctum');
// Update an item by id 
Route::put('/item/{id}',[ItemController::class, 'updateItem'])->middleware('auth:sanctum');

// Get item by category id
Route::get('/getitemsbycategory/{id}',[CategoryController::class, 'getItemByCategory'])->middleware('auth:sanctum');

//Increase number of poduct
Route::get('/increase/{id}',[ItemController::class, 'increaseAmount'])->middleware('auth:sanctum');

//Decrease number of poduct
Route::get('/decrease/{id}',[ItemController::class, 'decreaseAmount'])->middleware('auth:sanctum');


Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});