You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.8 KiB

  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Instruction;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\JsonResponse;
  6. class InstructionController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. */
  11. public function index(): JsonResponse
  12. {
  13. return response()->json();
  14. }
  15. /**
  16. * Show the form for creating a new resource.
  17. */
  18. public function create()
  19. {
  20. //
  21. }
  22. /**
  23. * Store a newly created resource in storage.
  24. */
  25. public function store(Request $request): JsonResponse
  26. {
  27. $request->validate([
  28. 'file' => 'required|file|mimes:json',
  29. 'frameworkID' => 'required|exists:frameworks,id',
  30. 'pageID' => 'required|exists:pages,id',
  31. ]);
  32. $file = $request->file('file');
  33. $path = $file->store('instructions', 'public');
  34. $instruction = Instruction::create([
  35. 'page_id' => $request->pageID,
  36. 'framework_id' => $request->frameworkID,
  37. 'file_path' => $path,
  38. ]);
  39. return response()->json([
  40. 'message' => 'Instruction saved successfully',
  41. 'instruction' => $instruction,
  42. ]);
  43. }
  44. /**
  45. * Display the specified resource.
  46. */
  47. public function show(Instruction $instruction)
  48. {
  49. //
  50. }
  51. /**
  52. * Show the form for editing the specified resource.
  53. */
  54. public function edit(Instruction $instruction)
  55. {
  56. //
  57. }
  58. /**
  59. * Update the specified resource in storage.
  60. */
  61. public function update(Request $request, Instruction $instruction)
  62. {
  63. //
  64. }
  65. /**
  66. * Remove the specified resource from storage.
  67. */
  68. public function destroy(Instruction $instruction)
  69. {
  70. //
  71. }
  72. }