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.
 
 
 
 

35 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.files.store') || ($request->route()->action['as'] == "api.files.show") || ($request->route()->action['as'] == 'api.files.update')) {
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);
}
}