first intial
Some checks failed
CI Pipeline / Lint & Test Frontend (push) Has been cancelled
CI Pipeline / Test Backend (push) Has been cancelled

This commit is contained in:
2025-09-16 22:59:46 +08:00
parent 64b5af061a
commit 6e7a8c784b
133 changed files with 31858 additions and 16 deletions

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Models\Material;
use Illuminate\Http\Request;
class MaterialController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
if ($request->has('category_id')) {
return Material::where('category_id', $request->category_id)->get();
}
return Material::all();
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$validated = $request->validate([
'category_id' => 'required|exists:categories,id',
'title' => 'required|string|max:255',
'author' => 'required|string|max:255',
'description' => 'nullable|string',
'cover_image_path' => 'nullable|string',
'file_path' => 'required|string',
'tags' => 'nullable|array',
]);
$material = Material::create($validated);
return response()->json($material, 201);
}
/**
* Display the specified resource.
*/
public function show(Material $material)
{
return $material;
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Material $material)
{
$validated = $request->validate([
'category_id' => 'sometimes|required|exists:categories,id',
'title' => 'sometimes|required|string|max:255',
'author' => 'sometimes|required|string|max:255',
'description' => 'nullable|string',
'cover_image_path' => 'nullable|string',
'file_path' => 'sometimes|required|string',
'tags' => 'nullable|array',
]);
$material->update($validated);
return response()->json($material);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Material $material)
{
$material->delete();
return response()->json(null, 204);
}
}