route()->action['as'] == 'api.files.store') { app()->singleton('collection', function () use ($request) { return Collection::where('name', $request->route('collection_name'))->firstOrFail(); }); } if ($request->route()->action['as'] == 'api.file.private') { app()->singleton('collection', function () use ($request) { return Collection::where('name', $request->route('collection_name'))->firstOrFail(); }); } return $next($request); } }