0

我有个问题。我创建了一个中间件来检查用户是否有图像。否则他会进入图片上传页面,他必须上传一张图片。不幸的是,在我的中间件重定向功能不起作用(我不知道为什么!)相反,我必须使用响应功能。如何发送带有响应功能(如重定向功能)的 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);
    }
}

4

1 回答 1

0

我已经解决了如下问题

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);
    }
于 2020-04-27T10:34:48.877 回答