Create a separate controller and add this
public function __construct()
{
$this->middleware('auth');
}
and you can uses the route
Route::get('admin/services/create',[
'middleware' => 'auth',
'uses' => 'ServicesController@create']);
I tried it, but if i try to see www.myapp.com/public for navigate my pages it redirect to www.myapp.com/public/home and gives me an error:
This webpage has a redirect loop
ERR_TOO_MANY_REDIRECTS
I'm trying on a brand new Laravel app, but i have problems anyway, if the user is NOT logged, i can navigate my pages, instead if the user IS logged, i can access only my private area, and i can't access to my other pages (in this case, my home /public), in fact if i try to go to www.myapp.com/public i am forced to be redirect to www.myapp.com/public/home, where there's my admin area.
Route::get('/', 'WelcomeController@index');
Route::get('home',['middleware' => 'auth', 'uses' => 'MiddlewareAuthController@index']);
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
according to your route mysite.com/index anyone can access and mysite.com/home only logged in users
Change it
Route::get('/', 'WelcomeController@index');
Route::get('home',['middleware' => 'auth', 'uses' => 'WelcomeController@home']);
and remove this if you have in your WelcomeController
public function __construct()
{
$this->middleware('auth');
}
Ok, this seems to works well. Just considering, if my route "home" (my private area view) and "/" (my public site) both points to WelcomeController, am i forced to use only one controller for both private and public areas?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.