lundi 29 août 2022

laravel response file problem in Prevent Back Button History middleware

Hi i am using laravel and I have created a PreventBack middleware to prevent users come back to page after logout

my middleware contains this Codes


namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class PreventBack
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        return $response->header('Cache-Control','no-cache, no-store, max-age=0, must-revalidate')
            ->header('Pragma','no-cache')
            ->header('Expires','Sun, 02 Jan 1990 00:00:00 GMT');
            

    }
}

but i have a route that returns the profile image.

Route::get('/profileimage', function () {

    return response()->file(   storage_path('profile_image.jpg')  );
});

when i put my profile image route in preventback middleware , this routes stops working and the route does not return the profile image.


Route::group(['middleware' => ['PreventBack']], function () {
    Route::get('/profileimage', function () {
        return response()->file(   storage_path('profile_image.jpg')  );
    }); 
});


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire