亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

laravel5.4 前后臺未登陸,跳轉到各自的頁面

laravel5.4 前后臺未登陸,跳轉到各自的頁面

PHP
超級無敵大壞蛋 2017-10-13 10:14:01
laravel我做了前后臺登陸,后臺未登錄跳轉到前臺登陸頁面了。 我想讓后臺未登入跳轉到后臺登陸頁面,前臺未登陸跳轉到前臺登陸頁面。config\auth.php?添加guards中的admin和providers中的admins<?php 'defaults'?=>?[ ????'guard'?=>?'web', ????'passwords'?=>?'users', ], 'guards'?=>?[ ????'web'?=>?[ ????????'driver'?=>?'session', ????????'provider'?=>?'users', ????], ????'api'?=>?[ ????????'driver'?=>?'token', ????????'provider'?=>?'users', ????], ????'admin'?=>?[ ????????'driver'?=>?'session', ????????'provider'?=>?'admins', ????], ], 'providers'?=>?[ ????'users'?=>?[ ????????'driver'?=>?'eloquent', ????????'model'?=>?App\User::class, ????], ????'admins'?=>?[ ????????'driver'?=>?'eloquent', ????????'model'?=>?App\AdminUser::class, ????], ], 'passwords'?=>?[ ????'users'?=>?[ ????????'provider'?=>?'users', ????????'table'?=>?'password_resets', ????????'expire'?=>?60, ????], ],路由//登陸頁面 Route::get('/login',?"\App\Http\Controllers\LoginController@index")->name('login'); //登陸行為 Route::post('/login',?"\App\Http\Controllers\LoginController@login"); Route::group(['middleware'?=>?'auth:web'],function?(){ ????Route::get('/posts',?'\App\Http\Controllers\PostController@index'); } //后臺 Route::group(['prefix'?=>?'admin'],?function()?{ ????Route::get('/login',?'\App\Admin\Controllers\LoginController@index'); ????Route::post('/login',?'\App\Admin\Controllers\LoginController@login'); ????Route::get('/logout',?'\App\Admin\Controllers\LoginController@logout'); ????Route::group(['middleware'?=>?'auth:admin'],function?(){ ????????Route::get('/home',?'\App\Admin\Controllers\HomeController@index'); ????}); });遇到的頁面跳轉問題
查看完整描述

3 回答

?
俠客島的含笑

TA貢獻552條經驗 獲得超285個贊

謝了哦

查看完整回答
反對 回復 2018-08-09
?
超級無敵大壞蛋

TA貢獻1條經驗 獲得超0個贊

需要在?App\Exceptions\Handler.php 文件修改

<?php

namespace?App\Exceptions;

use?Exception;
use?Illuminate\Auth\AuthenticationException;
use?Illuminate\Foundation\Exceptions\Handler?as?ExceptionHandler;

class?Handler?extends?ExceptionHandler
{
????/**
?????*?A?list?of?the?exception?types?that?should?not?be?reported.
?????*
?????*?@var?array
?????*/
????protected?$dontReport?=?[
????????\Illuminate\Auth\AuthenticationException::class,
????????\Illuminate\Auth\Access\AuthorizationException::class,
????????\Symfony\Component\HttpKernel\Exception\HttpException::class,
????????\Illuminate\Database\Eloquent\ModelNotFoundException::class,
????????\Illuminate\Session\TokenMismatchException::class,
????????\Illuminate\Validation\ValidationException::class,
????];

????/**
?????*?Report?or?log?an?exception.
?????*
?????*?This?is?a?great?spot?to?send?exceptions?to?Sentry,?Bugsnag,?etc.
?????*
?????*?@param??\Exception??$exception
?????*?@return?void
?????*/
????public?function?report(Exception?$exception)
????{
????????parent::report($exception);
????}

????/**
?????*?Render?an?exception?into?an?HTTP?response.
?????*
?????*?@param??\Illuminate\Http\Request??$request
?????*?@param??\Exception??$exception
?????*?@return?\Illuminate\Http\Response
?????*/
????public?function?render($request,?Exception?$exception)
????{
????????return?parent::render($request,?$exception);
????}

????/**
?????*?Convert?an?authentication?exception?into?an?unauthenticated?response.
?????*
?????*?@param??\Illuminate\Http\Request??$request
?????*?@param??\Illuminate\Auth\AuthenticationException??$exception
?????*?@return?\Illuminate\Http\Response
?????*/
????protected?function?unauthenticated($request,?AuthenticationException?$exception)
????{
????????if?($request->expectsJson())?{
????????????return?response()->json(['error'?=>?'Unauthenticated.'],?401);
????????}

????????if?(in_array('admin',?$exception->guards()))?{
????????????return?redirect()->guest('/admin/login');
????????}

????????return?redirect()->guest(route('login'));
????}
}


查看完整回答
反對 回復 2017-10-23
?
hallo_monde

TA貢獻3條經驗 獲得超1個贊

后端路由? 加上?

Route::get('/login',?'\App\Admin\Controllers\LoginController@index')->name('login');


查看完整回答
反對 回復 2017-10-14
  • 超級無敵大壞蛋
    超級無敵大壞蛋
    我前臺頁面登錄是寫的 Route::get('/login', "\App\Http\Controllers\LoginController@index")->name('login');
  • 3 回答
  • 0 關注
  • 2426 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號