2016-03-26 23 views
1

Oturum açtıktan sonra bir URL'ye yönlendirmede sorun yaşıyorum. Durum, bir kullanıcının bir blog gönderisini ziyaret etmesi ve yorum eklemeden önce giriş yapması gerektiğidir. Böylece kullanıcı giriş bağlantısını tıklar ve "auth/login" e giriş yapar ve her zaman "/ home" a yönlendirilir.Oturum açıldıktan sonra URL'ye laravel yönlendirmesi

Ben kullanıcı bir url "? Auth/giriş yönlendirme = url/to/blogpost"

gibi ayarlanır blogpost yönlendirilmek istiyorum ben şu Katman:

uygulama \ http Ara Katman \ \

Ara Katman \ kimliğini doğrulamak \

<?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 RedirectIfAuthenticated Eğer laravel 5'ten standart kimlik doğrulaması kullanıyorsanız

<?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); } } 
+1

http://stackoverflow.com/questions/15389833/laravel-redirect-back-to-original-destination-after-login – xdevnull

cevap

0

kopyalamak ve benim AuthController içine özellik AuthenticatesUsers ait getlogin fonksiyonunu yapıştırmak için karar verdik. Fonksiyonun üzerine yazarım VE özelliği olduğu gibi tutuyorum.

Sadece

ekledik

\Session::put('url.intended',\URL::previous());

0

, bir app/Http/Controllers/Auth/AuthController.php dosyayı bulmak ve buna $redirectPath değiştirin:

protected $redirectPath = '/url/to/blogpost'; 
1

Neden yeniden yönlendirici üzerinde amaçlanan yöntem kullanmıyorlar? Kimlik doğrulama filtresi tarafından yakalanmadan önce onlar erişmeye çalışıyorlardı URL'ye yönlendirir docs

yeniden yönlendirici üzerinde amaçlanan yöntem bu konuda okuyun. Hedeflenen hedefin mevcut olmaması durumunda, bu yönteme bir geri dönüş URI verilebilir.

İlgili konular