を使用して認証されていない場合は認証されない場合は、(ログインページです)私のインデックスページへLaravel 5.4は、ユーザーが、私は、ユーザーをリダイレクトするミドルウェア
はそれを動作させるように見えることはできません特定のページにリダイレクトし、私は本当にルーティングと混同しています。
にHomeController
class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return redirect()->guest('/');
}
}
ルーティング
// Index
Route::get('/', [
'as' => 'index',
'uses' => '[email protected]'
]);
UserControllerで
あなたは以下の通りですインデックス機能、でユーザコントローラへのリダイレクトを見るようにルーティング:
* __construct()はそう、それはミドルウェアを使用して「認証」を持っています。
public function __construct()
{
$this->middleware('auth');
}
public function index(){
// If user is logged
if(Auth::check()) {
// If user has NOT submitted information form redirect there, otherwise to categories
if(!Auth::user()->submitted_information)
return redirect()->route('information');
else
return redirect()->route('categories');
}
else
return view('index', ['body_class' => 'template-home']);
}
Handler.php
そして認証されていない機能認証のミドルウェア内部(例外/ Handler.php)
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->route('index');
}
私は今取得エラーがあります以下:
InvalidArgumentException in UrlGenerator.php line 304:
Route [index] not defined.
このエラーは、上記非認証関数で
return redirect()->route('index');
ラインの起こります。
ここには何が欠けていますか?それ以上の情報が必要な場合はお気軽にお問い合わせください。
EDIT:今まで、私はUserControllerでから__construct()
メソッドを削除し、それがどのような作品middleware
使用するには、すべてのルートにweb.php
に挿入した場合。
Route::get('/categories', [
'as' => 'categories',
'uses' => '[email protected]'
])->middleware('auth');
しかし、私は自動的にそれを使用するために、使用するどのようなミドルウェアが指定しなくても、検索しようとしています。例えば
。
いいえ、それは正しいルーティングを表示する助けにはなりませんでしたが、現在ネットワークループが常に "/" –