我有个问题。我创建了一个中间件来检查用户是否有图像。否则他会进入图片上传页面,他必须上传一张图片。不幸的是,在我的中间件重定向功能不起作用(我不知道为什么!)相反,我必须使用响应功能。如何发送带有响应功能(如重定向功能)的 Flash 消息?希望你能帮助我。
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class CheckUserDataMiddleware
{
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Checking through relations if the User has already an image
if (empty(auth()->user()->profile->image)) {
return response()
->view('pages.image.create', [], 200)
->header('Content-Type', $type = '');
// return redirect()
// ->route('image.create')
// ->with('info', trans('To complete your profile, we request you to upload a clear photo of yourself.'));
}
return $next($request);
}
}