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.

39 lines
1.2 KiB

  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Models\Collection;
  4. use Closure;
  5. use Illuminate\Http\Request;
  6. use Illuminate\support\Str;
  7. class BindCollectionModelMiddleware
  8. {
  9. /**
  10. * Handle an incoming request.
  11. *
  12. * @param \Illuminate\Http\Request $request
  13. * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
  14. * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
  15. */
  16. public function handle(Request $request, Closure $next)
  17. {
  18. if ($request->route()->action['as'] == 'api.file.store') {
  19. app()->bind('collection', function () use ($request) {
  20. return Collection::where('name', $request->route('collections_name'))->get();
  21. });
  22. app()->singleton('getFileUuid', function () {
  23. return Str::uuid();
  24. });
  25. }
  26. if ($request->route()->action['as'] == 'api.file.private') {
  27. app()->bind('collection', function () use ($request) {
  28. return Collection::where('name', $request->route('collections_name'))->get();
  29. });
  30. }
  31. return $next($request);
  32. }
  33. }