在 Laravel 7 中通过响应函数发送即显消息
Sending flash message via Response Function in Laravel 7
我有一个问题。
我创建了一个中间件来检查用户是否有图像。否则,他会转到图像上传页面,并且他必须上传图像。
不幸的是,在我的中间件中,重定向功能不起作用(我不知道为什么!)相反,我必须使用响应功能。
如何发送带有重定向功能等响应功能的即闪消息?
希望你能帮助我。
<?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);
}
我有一个问题。 我创建了一个中间件来检查用户是否有图像。否则,他会转到图像上传页面,并且他必须上传图像。 不幸的是,在我的中间件中,重定向功能不起作用(我不知道为什么!)相反,我必须使用响应功能。 如何发送带有重定向功能等响应功能的即闪消息? 希望你能帮助我。
<?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);
}