Tracy Bauer
Tracy Bauer

Reputation: 41

Laravel Change URL First page Routes

I have an Laravel 5.4 Website with User Login. If i enter the Url the script redirect to Login page, not "home" of course.

I want now an new Page if i enter the URL not Login Page. An Page with Login Button and after it goes to Login page. I have created an new blade where i want as first page: start.blade.php

How i can change this?

I have try it with my code in web.php but dont work, my Code:

Route::group(['middleware' => 'auth'],function(){
  Route::get('logout','AuthController@Logout')->name('logout');
  Route::get('/', 'HomeController@index')->name('home');
  Route::get('myprofile','ProfileController@Index')->name('profile');

Upvotes: 1

Views: 8080

Answers (2)

Maraboc
Maraboc

Reputation: 11083

You have to add a new route for your page outside the group :

Route::get('start','tController@start')->name('start');
Route::group(['middleware' => 'auth'],function(){
  Route::get('logout','AuthController@Logout')->name('logout');
  Route::get('/', 'HomeController@index')->name('home');
  Route::get('myprofile','ProfileController@Index')->name('profile');
}

And then you have to change in the Exceptions->Handler.php :

protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);
    }

    return redirect()->guest(route('login')); // <-- change here :)
}

You have to change return redirect()->guest(route('login')); to your new route :)

return redirect()->guest(route('start'));

Upvotes: 1

Surabhi
Surabhi

Reputation: 179

Add a new route in your routes.php file with no middleware attached to it. Use this:-

Route::get('start','StartController@start')->name('start');

Now your routes.php file should looks like this :-

// Newly added route for handling pre-login calls.
Route::get('start','StartController@start')->name('start');

Route::group(['middleware' => 'auth'],function(){
  Route::get('logout','AuthController@Logout')->name('logout');
  Route::get('/', 'HomeController@index')->name('home');
  Route::get('myprofile','ProfileController@Index')->name('profile');
});

You need to create a new controller StartController with a function named start to achieve this without disturbing current structure of code.

start function in controller:-

public function start() {
 return view('< new view name here >');
}

Upvotes: 1

Related Questions