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.

45 lines
1.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Documents\PolicyDocument;
  4. use App\Http\Resources\CollectionResource;
  5. use App\Models\Collection;
  6. use App\Utilities\Polices\BasePolicy;
  7. use Illuminate\Http\Request;
  8. class CollectionController extends Controller
  9. {
  10. public function show(Collection $collection)
  11. {
  12. BasePolicy::allow(app('modelDocument')?->getPolicy,$collection);
  13. return new CollectionResource($collection);
  14. }
  15. public function store(Request $request)
  16. {
  17. BasePolicy::allow(app('modelDocument')?->storePolicy);
  18. $collection = Collection::create($request->all());
  19. return new CollectionResource($collection);
  20. }
  21. public function update(Request $request, Collection $collection)
  22. {
  23. BasePolicy::allow(app('modelDocument')?->updatePolicy, $collection);
  24. $collection->update($request->all());
  25. return new CollectionResource($collection);
  26. }
  27. public function destroy(Collection $collection)
  28. {
  29. BasePolicy::allow(app('modelDocument')?->{$collection->trashed() ? 'restorePolicy' : 'deletePolicy'},$collection);
  30. if ($collection->trashed()) {
  31. return $collection->restore();
  32. }
  33. return $collection->delete();
  34. }
  35. }