【发布时间】:2019-05-31 08:15:27
【问题描述】:
我正在学习 laravel,但我的基本 URL 有问题,即 http://localhost/。
它不断重定向到http://localhost/home,这是基本身份验证路由,由于我没有登录,它会将我重定向到http://localhost/login。
我希望 http://localhost/ 按原样重定向到 http://localhost/blog/posts。
我这样做是因为将来基本 url 将重定向到另一个页面。在那之前,我想显示博客文章。
web.php
Route::get('/', [
'as' => 'index',
'uses' => 'HomeController@index',
]);
Route::get('/blog/posts', [
'as' => 'blog',
'uses' => 'BlogController@index'
]);
Auth::routes();
Route::get('/home', [
'as' => 'home',
'uses' => 'HomeController@home'
]);
HomeController.php
public function home()
{
return view('home');
}
public function index()
{
return view('blog');
}
我希望我已经足够清楚了,如果需要,我很乐意提供更多信息。
问题已解决:
注释或删除 HomeController.php 中的$this->middleware('auth'); 并将其添加到路由中:
Route::get('/home', [
'as' => 'home',
'uses' => 'HomeController@home'
])->middleware('auth');
【问题讨论】:
标签: laravel laravel-routing laravel-authentication