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.
 
 
 
 

31 lines
853 B

<?php
namespace App\Http\Middleware;
use App\Models\File;
use Closure;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
class BindFileModelMiddleware
{
/**
* 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') {
if(is_null($request->file('file'))){
app()->bind('file', function () use ($request) {
return File::find($request->file);
});
}
}
return $next($request);
}
}