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

<?php
namespace App\Http\Middleware;
use App\Models\Collection;
use Closure;
use Illuminate\Http\Request;
use Illuminate\support\Str;
class BindCollectionModelMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if ($request->route()->action['as'] == 'api.file.store') {
app()->bind('collection', function () use ($request) {
return Collection::where('name', $request->route('collections_name'))->get();
});
app()->singleton('getFileUuid', function () {
return Str::uuid();
});
}
if ($request->route()->action['as'] == 'api.file.private') {
app()->bind('collection', function () use ($request) {
return Collection::where('name', $request->route('collections_name'))->get();
});
}
return $next($request);
}
}