Laravel 5 ignore specific authentication route

I am new to laravel 5. I have a dashboard page and a login page. whenever i go to localhost:8080/dashboard

, it always redirects me to localhost:8080/auth/login

.

I wanted to show my panel localhost:8080/dashboard

for browsing without logging in first. Here is my code inVerifyCsfrToken

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');

   }

      

+3


source to share


1 answer


Here's what's causing the problem:

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

      



It restricts access to the login page. Just remove it from your controller and users will be able to access the page regardless of whether they are logged in or not.

+3


source







All Articles