LibraryController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Http\Controllers\API;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\API\Library\CreateOrUpdateRequest;
  5. use App\Http\Resources\API\LibraryResource;
  6. use App\Models\Library;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Auth;
  9. class LibraryController extends Controller
  10. {
  11. /**
  12. * Display a listing of the resource.
  13. */
  14. public function index()
  15. {
  16. //
  17. }
  18. /**
  19. * Store a newly created resource in storage.
  20. */
  21. public function store(CreateOrUpdateRequest $request)
  22. {
  23. Library::query()->create([
  24. ...$request->all(),
  25. 'created_by' => Auth::id(),
  26. 'company_id' => Auth::user()->company_id,
  27. 'whitelist' => $request->whitelist ? sprintf(",%s", implode(',', $request->whitelist)) : null,
  28. ]);
  29. return $this->created();
  30. }
  31. /**
  32. * Display the specified resource.
  33. */
  34. public function show(string $id)
  35. {
  36. $library = Library::query()->findOrFail($id);
  37. return new LibraryResource($library);
  38. }
  39. /**
  40. * Update the specified resource in storage.
  41. */
  42. public function update(Request $request, string $id)
  43. {
  44. $library = Library::query()->findOrFail($id);
  45. $library->fill($request->only([
  46. 'name', 'acl', 'asset_id', 'project_id',
  47. ]));
  48. $library->whitelist = $request->whitelist ? sprintf(",%s", implode(',', $request->whitelist)) : null;
  49. $library->save();
  50. return $this->noContent();
  51. }
  52. /**
  53. * Remove the specified resource from storage.
  54. */
  55. public function destroy(string $id)
  56. {
  57. //
  58. }
  59. }