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.

53 lines
1.2 KiB

2 years ago
  1. <?php
  2. namespace App\iLaravel;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Resources\Successful;
  5. use App\Models\ILaravel;
  6. use App\Utilities\Polices\BasePolicy;
  7. use Illuminate\Http\Request;
  8. class ILaravelController extends Controller
  9. {
  10. // this method check AuthServiceProvider
  11. public function me()
  12. {
  13. return auth()->user();
  14. }
  15. public function store(Request $request)
  16. {
  17. BasePolicy::allow(app('modelDocument')?->storePolicy);
  18. return ILaravel::create($request->all());
  19. }
  20. public function show(ILaravel $ILaravel)
  21. {
  22. BasePolicy::allow(app('modelDocument')?->getPolicy, $ILaravel);
  23. return $ILaravel;
  24. }
  25. public function update(ILaravel $ILaravel, Request $request)
  26. {
  27. BasePolicy::allow(app('modelDocument')?->updatePolicy, $ILaravel);
  28. $ILaravel->update($request->all());
  29. return $ILaravel;
  30. }
  31. public function destroy(ILaravel $ILaravel)
  32. {
  33. BasePolicy::allow(app('modelDocument')?->{$ILaravel->trashed() ? 'restorePolicy' : 'deletePolicy'}, $ILaravel);
  34. if ($ILaravel->trashed()) {
  35. return tap($ILaravel, fn() => $ILaravel->restore());
  36. }
  37. $ILaravel->delete();
  38. return Successful::make();
  39. }
  40. }