我有一个问题。我创建了一个中间件来检查用户是否有图像。否则,他将转到图像上传页面,并且必须上传图像。不幸的是,在我的中间件中,重定向功能不起作用(我不知道为什么!),我不得不使用响应功能。如何发送带有响应功能(如重定向功能)的即时消息?希望你能帮助我。
<?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);
}
}
我已经解决了以下问题
public function handle($request, Closure $next)
{
// Checking through relations if the User has already an image
if (empty(auth()->user()->profile->image)) {
if (!$request->routeIs('image.create')) {
if (!$request->isMethod('post')) {
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);
}