php – Laravel 5忽略身份验证特定的路由

我是laravel 5的新手.我有一个仪表板页面和一个登录页面.无论何时我去localhost:8080 /仪表板,它总是将我重定向到localhost:8080 / auth / login.

我想显示我的仪表板localhost:8080 /仪表板,无需先登录即可查看.这是我在VerifyCsfrToken中的代码

namespace App\Http\Middleware;

use Closure;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier {

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */


    protected $except_urls = [
        'dashboard/dashboard',
    ];

    public function handle($request, Closure $next)
    {
        $regex = '#' . implode('|', $this->except_urls) . '#';

        if ($this->isReading($request) || $this->tokensMatch($request) || preg_match($regex, $request->path()))
        {
            return $this->addCookieToResponse($request, $next($request));
        }

        throw new TokenMismatchException;

        return parent::handle($request, $next);
    }

}

routes.php文件

Route::get('dashboard', 'ReservationController@index');

 Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
 ]);

控制器:

use App\reservations;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Console\Scheduling\Schedule;
use Carbon\Carbon;
use Request;

class ReservationController extends Controller {

/*
|--------------------------------------------------------------------------
| Welcome Controller
|--------------------------------------------------------------------------
|
| This controller renders the "marketing page" for the application and
| is configured to only allow guests. Like most of the other sample
| controllers, you are free to modify or remove it as you desire.
|
*/

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('auth');
}

/**
 * Show the application welcome screen to the user.
 *
 * @return Response
 */

public function schedule()
{
    $schedules = schedules::all();


    return view('calendar.schedule',compact('schedules'));
}
public function index()
{
return view('dashboard.dashboard');
}
public function create()
{

    return view('reserve.reserve');
}
public function update()
{
    return view('calendar.update');
}
public function login()
{
    return view('login');
}

public function store(Requests\CreateReservationRequest $request)
{

    $input = Request::all();
    $reservation = new reservations(['user_id'       => '13100024',
                                    'status_id'     => '1',
                                    'room_id'       => $input['room'],
                                    'purpose'       => $input['purpose'],
                                    'start_time'    => $input['date']."        ".$input['hour1'].":".$input['minute1'].":00",
                                    'end_time'      => $input['date']." ".$input['hour2'].":".$input['minute2'].":00",
                                    'add_date'      => Carbon::now()
                                    ]);
    $reservation->save();

    return "success";
   // return redirect('schedule');

   }
最佳答案
这是导致问题的原因:

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('auth');
}

它限制对登录用户的页面访问.只需将其从控制器中删除,用户就可以访问该页面,无论他们是否已登录.

转载注明原文:php – Laravel 5忽略身份验证特定的路由 - 代码日志