Ich habe Probleme mit der Umleitung auf eine URL nach der Anmeldung. Die Situation ist, dass jemand einen Blogpost besucht und sich vor dem Hinzufügen eines Kommentars anmelden muss. Der Benutzer klickt also auf den Login-Link und meldet sich "auth/login" an und wird immer auf "/ home" umgeleitet.Laravel Umleitung auf URL nach dem Login
Ich möchte der Benutzer auf die Blogpost umgeleitet werden, wenn eine URL festgelegt ist, wie "Auth/login redirect = url/to/Blogpost?"
Ich habe folgende Middleware:
app \ http \ Middleware \ RedirectIfAuthenticated
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class RedirectIfAuthenticated
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->check()) {
return redirect('/home');
}
return $next($request);
}
}
app \ http \ Middleware \ Authentifizieren
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class Authenticate
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
}
return $next($request);
}
}
http://stackoverflow.com/questions/15389833/laravel-redirect-back-to-original-destination-after-login – xdevnull