我是laravel的初学者,如果用户登录,我正尝试重定向到另一条路线,注册和登录工作正常,这不是问题,但是当我尝试执行操作时
@if(Auth::check())
{{
redirect()->route('news')
}}
@endif
重定向脚本将在屏幕上输出,如下所示:
HTTP/1.0 302 Found Cache-Control: no-cache, private Location: http://localhost/red-sec/public/news <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta http-equiv="refresh" content="1;url=http://localhost/red-sec/public/news" /> <title>Redirecting to http://localhost/red-sec/public/news</title> </head> <body> Redirecting to <a href="http://localhost/red-sec/public/news">http://localhost/red-sec/public/news</a>. </body> </html>
请原谅我如果我是菜鸟错误,我是laravel的新手,新闻路由设置正确并且正在运行
编辑1:对于第一个评论,是的,这是我的web.php文件:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
})->name('home');
Route::post('/signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
Route::post('/signin', [
'uses' => 'UserController@postSignIn',
'as' => 'signin'
]);
Route::get('/news', [
'uses' => 'userController@getNews',
'as' => 'news',
'middleware' => 'auth'
]);
您不应该尝试(也不能)重定向视图。视图只能用于显示数据,不能用于业务逻辑。
因为您没有使用控制器执行任何逻辑(您直接从路由器返回视图),所以可以执行以下操作:
Route::get('/', function () {
if(Auth::check()) {
return redirect()->route('news');
}
return view('welcome');
})->name('home');
视图中显示的文本实际上是HTTP响应。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句