我是laravel 5的新手。我有一个仪表板页面和一个登录页面。每当我转到localhost:8080/dashboard
时,它总会将我重定向到localhost:8080/auth/login
。
我希望在不先登录的情况下显示我的信息中心localhost:8080/dashboard
。这是我在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');
}
答案 0 :(得分:5)
这是导致问题的原因:
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
它限制对登录用户的页面访问。只需将其从控制器中删除,用户就可以访问该页面,无论他们是否已登录。
答案 1 :(得分:-1)
public function __construct()
{
$this->middleware('auth', ['except' => ['Whatever You want to Bypass']]);
}