I am new in laravel 5. I have a dashboard page and a login page. whenever I go to localhost:8080/dashboard
it always redirect me to localhost:8080/auth/login
.
I wanted to show my dashboard localhost:8080/dashboard
to be viewed without logging in first. Here is my code in 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',
]);
controller :
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');
}
This is what causes the issue:
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
It restricts access to the page to logged in users. Just remove it from your controller and users will be able to access the page whether they're logged in or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With