Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions app/Http/Controllers/PackCategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Http\Controllers;

use App\Models\Pack;
use App\Models\PackCategory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class PackCategoryController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Pack $pack)
{
//
return $pack->categories;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request, Pack $pack)
{
//
$validator = Validator::make($request->all(), [
'category_id' => 'required|exists:categories,id',
]);

if ($validator->fails()) {
return response()->json([
'message' => 'The given data was invalid.',
'errors' => $validator->errors(),
], 422);
}

$pack->categories()->create($request->all());

return response()->json(['message' => 'Pack Category added successfully.'], 201);
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Pack $pack, PackCategory $packCategory)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the pack variable if it is not used

{
//
$packCategory->delete();
return response()->json(['message' => 'PackCategory deleted successfully.']);
}
}
44 changes: 12 additions & 32 deletions app/Http/Controllers/StickerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,44 @@

namespace App\Http\Controllers;

use App\Models\Pack;
use App\Models\Sticker;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rules\File;

class StickerController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
public function index(Pack $pack)
{
//
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
return $pack->stickers();
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
public function store(Request $request, Pack $pack)
{
//

}

/**
* Display the specified resource.
*/
public function show(Sticker $sticker)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Sticker $sticker)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, Sticker $sticker)
public function show(Pack $pack, Sticker $sticker)
{
//
return $sticker;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use standard json response

}

/**
* Remove the specified resource from storage.
*/
public function destroy(Sticker $sticker)
public function destroy(Pack $pack, Sticker $sticker)
{
//
$sticker->delete();
return response()->json(['message' => 'Sticker deleted successfully.']);
}
}
6 changes: 6 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use App\Http\Controllers\auth\LogoutController;
use App\Http\Controllers\auth\RegisterController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\PackCategoryController;
use App\Http\Controllers\PackController;
use App\Http\Controllers\StickerController;
use Illuminate\Support\Facades\Route;


Expand All @@ -20,4 +22,8 @@

Route::apiResource('category', CategoryController::class);
Route::apiResource('pack', PackController::class);
Route::apiResource('pack.sticker', StickerController::class)
->except('update');
Route::apiResource('pack.category', PackCategoryController::class)
->except(['update', 'show']);
});